Skip to content

Commit 23447e1

Browse files
committed
feat(oauth): initialize oauth for google and facebook
1 parent 3eb62f5 commit 23447e1

File tree

15 files changed

+5291
-1433
lines changed

15 files changed

+5291
-1433
lines changed

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ JWT_EXPIRATION = 4h
3131
REFRESH_TOKEN_EXPIRES = 7d
3232
PASSWORD_RESET_EXPIRES = 10m
3333

34+
# Oauth Google
35+
GOOGLE_CLIENT_ID =
36+
GOOGLE_CLIENT_SECRET =
37+
GOOGLE_REDIRECT_URI =
38+
39+
# Oauth Facebook
40+
FACEBOOK_APP_ID =
41+
FACEBOOK_APP_SECRET =
42+
FACEBOOK_REDIRECT_URI =
43+
3444
# SMTP
3545
SMTP_PORT =
3646
SMTP_HOST =

database/migrations/scripts/base/tables/create-users.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@ module.exports = {
1414
type: Sequelize.STRING,
1515
allowNull: false,
1616
},
17-
username: {
18-
type: Sequelize.STRING,
19-
allowNull: false,
20-
},
21-
password: {
22-
type: Sequelize.STRING,
23-
allowNull: false,
24-
},
17+
username: Sequelize.STRING,
18+
password: Sequelize.STRING,
2519
is_admin: {
2620
type: Sequelize.BOOLEAN,
2721
allowNull: false,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/** @type {import('sequelize-cli').Migration} */
2+
module.exports = {
3+
async up(queryInterface, Sequelize) {
4+
// add column
5+
await queryInterface.addColumn('auth_provider', 'user_id', {
6+
type: Sequelize.INTEGER,
7+
allowNull: false,
8+
});
9+
10+
// add constraint
11+
await queryInterface.addConstraint('auth_provider', {
12+
fields: ['user_id'],
13+
type: 'foreign key',
14+
name: 'auth_provider_users_user_id',
15+
references: {
16+
table: 'users',
17+
field: 'id',
18+
},
19+
onUpdate: 'CASCADE',
20+
onDelete: 'CASCADE',
21+
});
22+
},
23+
async down(queryInterface) {
24+
if (await queryInterface.tableExists('auth_provider')) {
25+
// remove constraint
26+
await queryInterface.removeConstraint('auth_provider', 'auth_provider_users_user_id');
27+
28+
// remove column
29+
await queryInterface.removeColumn('auth_provider', 'user_id');
30+
}
31+
},
32+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/** @type {import('sequelize-cli').Migration} */
2+
module.exports = {
3+
async up(queryInterface, Sequelize) {
4+
await queryInterface.createTable(
5+
'auth_provider',
6+
{
7+
id: {
8+
allowNull: false,
9+
autoIncrement: true,
10+
primaryKey: true,
11+
type: Sequelize.INTEGER,
12+
},
13+
provider: {
14+
type: Sequelize.STRING,
15+
allowNull: false,
16+
},
17+
provider_id: {
18+
type: Sequelize.STRING,
19+
allowNull: false,
20+
},
21+
metadata: {
22+
type: Sequelize.JSON,
23+
allowNull: true,
24+
},
25+
created_at: {
26+
allowNull: false,
27+
type: Sequelize.DATE,
28+
},
29+
updated_at: {
30+
allowNull: false,
31+
type: Sequelize.DATE,
32+
},
33+
},
34+
{
35+
charset: 'utf8mb4',
36+
collate: 'utf8mb4_unicode_ci',
37+
},
38+
);
39+
40+
await queryInterface.addConstraint('auth_provider', {
41+
type: 'unique',
42+
name: 'auth_provider_provider_provider_id',
43+
fields: ['provider', 'provider_id'],
44+
});
45+
},
46+
47+
async down(queryInterface) {
48+
if (await queryInterface.tableExists('auth_provider')) {
49+
await queryInterface.dropTable('auth_provider');
50+
}
51+
},
52+
};

0 commit comments

Comments
 (0)