I’m using passport.js and I’m wounding if I can link a facebook id to a logged in user’s account. Something like this:
passport.use( new FacebookStrategy({
consumerKey: ---
consumerSecret: ---
callbackURL: "http://mycallback"
},
function(token, tokenSecret, profile, done) {
if (user is logged in)
user = User.addfacebookId(user, profile.id)
done(user);
}
}
));
There’s a few ways to approach this, but I think one of the most straight-forward is to use the
passReqToCallbackoption. With that enabled,reqbecomes the first argument to the verify callback, and from there you can check to see ifreq.userexists, which means the user is already logged in. At that point, you can associate the user with Facebook profile details and supply the same user instance to the done callback. Ifreq.userdoes not exist, just handle it as usual.For example: