Created
April 16, 2015 02:52
-
-
Save BrentAureli/b01ab1d97e118413ec7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
passport.use(new FacebookStrategy({ | |
clientID: configAuth.facebookAuth.clientID, | |
clientSecret: configAuth.facebookAuth.clientSecret, | |
callbackURL: configAuth.facebookAuth.callbackURL, | |
passReqToCallback: true | |
}, | |
function(req, accessToken, refreshToken, profile, done) { | |
process.nextTick(function(){ | |
//user is not logged in yet | |
User.findOne({'facebook.id': profile.id}, function(err, user){ | |
if(err) | |
return done(err); | |
if(user){ | |
user.generateToken(); | |
return done(null, user); | |
} | |
else { | |
var newUser = new User(); | |
newUser.facebook.id = profile.id; | |
newUser.facebook.token = accessToken; | |
newUser.facebook.name = profile.name.givenName + ' ' + profile.name.familyName; | |
newUser.facebook.email = profile.emails[0].value; | |
newUser.generateToken(); | |
newUser.save(function(err){ | |
if(err) | |
throw err; | |
return done(null, newUser); | |
}) | |
} | |
}); | |
}); | |
} | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment