Skip to content

Commit

Permalink
feat(authentication): user provider metadata stored in database (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdimitris committed Feb 16, 2022
1 parent 5d19a70 commit 3863224
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,11 @@ export abstract class OAuth2<T extends Payload, S extends OAuth2Settings> {
);
}

if (isNil(user[this.providerName])) {
user[this.providerName] = payload;
// TODO look into this again, as the email the user has registered will still not be verified
if (!user.isVerified) user.isVerified = true;
user = await User.getInstance().findByIdAndUpdate(user._id, user);
}
user[this.providerName] = payload;
// TODO look into this again, as the email the user has registered will still not be verified
if (!user.isVerified) user.isVerified = true;
user = await User.getInstance().findByIdAndUpdate(user._id, user);

} else {
user = await User.getInstance().create({
email: payload.email,
Expand Down
2 changes: 1 addition & 1 deletion modules/authentication/src/handlers/facebook/facebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class FacebookHandlers extends OAuth2<Payload, FacebookSettings> {
let payload: FacebookUser = {
id: facebookResponse.data.id,
email: facebookResponse.data.email,
data: {},
data: { ...facebookResponse.data },
};
return payload;
}
Expand Down
63 changes: 54 additions & 9 deletions modules/authentication/src/models/User.schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ConduitActiveSchema,
DatabaseProvider,
TYPE,
} from '@conduitplatform/grpc-sdk';
import { ConduitActiveSchema, DatabaseProvider, TYPE } from '@conduitplatform/grpc-sdk';

const schema = {
_id: TYPE.ObjectId,
Expand All @@ -25,6 +21,9 @@ const schema = {
tokenExpires: {
type: TYPE.Date,
},
data: {
type: TYPE.JSON,
},
},
google: {
id: {
Expand All @@ -36,6 +35,9 @@ const schema = {
tokenExpires: {
type: TYPE.Date,
},
data: {
type: TYPE.JSON,
},
},
microsoft: {
id: {
Expand All @@ -47,6 +49,9 @@ const schema = {
tokenExpires: {
type: TYPE.Date,
},
data: {
type: TYPE.JSON,
},
},
figma: {
id: {
Expand All @@ -58,6 +63,9 @@ const schema = {
tokenExpires: {
type: TYPE.Date,
},
data: {
type: TYPE.JSON,
},
},
slack: {
id: {
Expand All @@ -69,6 +77,9 @@ const schema = {
tokenExpires: {
type: TYPE.Date,
},
data: {
type: TYPE.JSON,
},
},
facebook: {
id: {
Expand All @@ -77,9 +88,12 @@ const schema = {
token: {
type: TYPE.String,
},
// tokenExpires: {
// type: TYPE.String,
// },
tokenExpires: {
type: TYPE.String,
},
data: {
type: TYPE.JSON,
},
},
kakao: {
id: {
Expand All @@ -104,6 +118,9 @@ const schema = {
tokenExpires: {
type: TYPE.String,
},
data: {
type: TYPE.JSON,
},
profile_image_url: TYPE.String,
},
active: {
Expand Down Expand Up @@ -146,11 +163,13 @@ export class User extends ConduitActiveSchema<User> {
id: string;
token: string;
tokenExpires: Date;
data: any;
};
facebook?: {
id: string;
token: string;
// tokenExpires: string;
//tokenExpires: string;
data: any;
};
kakao?: {
id: string;
Expand All @@ -164,7 +183,33 @@ export class User extends ConduitActiveSchema<User> {
token: string;
tokenExpires: string;
profile_image_url?: string;
data: any;
};
slack?: {
id: string;
token: string;
tokenExpires: Date;
data: any;
};
figma?: {
id: string;
token: string;
tokenExpires: Date;
data: any;
};
microsoft?: {
id: string;
token: string;
tokenExpires: Date;
data: any;
};
github?: {
id: string;
token: string;
tokenExpires: Date;
data: any;
};

active: boolean;
isVerified: boolean;
hasTwoFA: boolean;
Expand Down

0 comments on commit 3863224

Please sign in to comment.