feat: facebook auth module

This commit is contained in:
Nick
2019-04-28 02:11:38 -04:00
parent 2abecea09c
commit c03dae933f
3 changed files with 32 additions and 15 deletions

View File

@@ -5,6 +5,7 @@
// ------------------------------------
const FacebookStrategy = require('passport-facebook').Strategy
const _ = require('lodash')
module.exports = {
init (passport, conf) {
@@ -13,13 +14,21 @@ module.exports = {
clientID: conf.clientId,
clientSecret: conf.clientSecret,
callbackURL: conf.callbackURL,
profileFields: ['id', 'displayName', 'email']
}, function (accessToken, refreshToken, profile, cb) {
WIKI.models.users.processProfile(profile).then((user) => {
return cb(null, user) || true
}).catch((err) => {
return cb(err, null) || true
})
profileFields: ['id', 'displayName', 'email', 'photos'],
authType: 'reauthenticate'
}, async (accessToken, refreshToken, profile, cb) => {
try {
const user = await WIKI.models.users.processProfile({
profile: {
...profile,
picture: _.get(profile, 'photos[0].value', '')
},
providerKey: 'facebook'
})
cb(null, user)
} catch (err) {
cb(err, null)
}
}
))
}