mirror of
https://github.com/wassname/talk.git
synced 2026-07-01 22:24:08 +08:00
Added fix for facebook
This commit is contained in:
@@ -102,7 +102,10 @@ if (process.env.TALK_FACEBOOK_APP_ID && process.env.TALK_FACEBOOK_APP_SECRET &&
|
||||
clientID: process.env.TALK_FACEBOOK_APP_ID,
|
||||
clientSecret: process.env.TALK_FACEBOOK_APP_SECRET,
|
||||
callbackURL: `${process.env.TALK_ROOT_URL}/api/v1/auth/facebook/callback`,
|
||||
profileFields: ['id', 'username', 'picture.type(large)']
|
||||
|
||||
// TODO: remove displayName reference when we have steps in the FE to handle
|
||||
// the username create flow.
|
||||
profileFields: ['id', 'displayName', 'picture.type(large)']
|
||||
}, (accessToken, refreshToken, profile, done) => {
|
||||
UsersService
|
||||
.findOrCreateExternalUser(profile)
|
||||
|
||||
+8
-10
@@ -105,13 +105,13 @@ module.exports = class UsersService {
|
||||
* @param {Object} profile - User social/external profile
|
||||
* @param {Function} done [description]
|
||||
*/
|
||||
static findOrCreateExternalUser(profile) {
|
||||
static findOrCreateExternalUser({id, provider, displayName}) {
|
||||
return UserModel
|
||||
.findOne({
|
||||
profiles: {
|
||||
$elemMatch: {
|
||||
id: profile.id,
|
||||
provider: profile.provider
|
||||
id,
|
||||
provider
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -122,14 +122,12 @@ module.exports = class UsersService {
|
||||
|
||||
// The user was not found, lets create them!
|
||||
user = new UserModel({
|
||||
username: profile.username,
|
||||
|
||||
// TODO: remove displayName reference when we have steps in the FE to handle
|
||||
// the username create flow.
|
||||
username: displayName.replace(/ /g, '_').replace(/[^a-zA-Z_]/g, ''),
|
||||
roles: [],
|
||||
profiles: [
|
||||
{
|
||||
id: profile.id,
|
||||
provider: profile.provider
|
||||
}
|
||||
]
|
||||
profiles: [{id, provider}]
|
||||
});
|
||||
|
||||
return user.save();
|
||||
|
||||
Reference in New Issue
Block a user