Added fix for facebook

This commit is contained in:
Wyatt Johnson
2017-02-09 17:03:41 -07:00
parent 3cd2b28bc2
commit 7db3da5fdd
2 changed files with 12 additions and 11 deletions
+4 -1
View File
@@ -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
View File
@@ -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();