Skip to content

Instantly share code, notes, and snippets.

@BrentAureli
Created April 16, 2015 02:52
Show Gist options
  • Save BrentAureli/b01ab1d97e118413ec7c to your computer and use it in GitHub Desktop.
Save BrentAureli/b01ab1d97e118413ec7c to your computer and use it in GitHub Desktop.
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