Hi! I have a question regarding passport strategies.
I read many many topics about because the app I’m working on right now is my very first one full stack, and I needed to understand how it works and how to solve the numerous issues I encountered
My authentication strategies now work fine but I have a question because I don’t understand something:
I eventually had a problem(facebook and twitter only, regarding local auth, I hav 2 middlewares before login, including one for user db creation): I needed to "login " once to create user, then had a failureRedirect because user was saved but not present in req, then I had to login again and user was found in db and logged in.
The issue came from the way I created my user:
// if no user found in db:
else {
const twitterUser = new Auth({
'twitter.id': profile.id,
'twitter.token': accessToken,
'twitter.name': profile.displayName,
}).save(((err) => {
if(err) {
console.log('err: ' + err);
done(err);
}
done(null, twitterUser);
}));
}
});
}
));
then i eventually changed it by doing so
else {
const facebookUser = new Auth();
facebookUser.facebook.id = profile.id;
facebookUser.facebook.token = accessToken;
facebookUser.facebook.name = profile.displayName;
facebookUser.save(((err) // blablabla
and it worked just fine this way, req.user ok and user saved and logged in at once.
I must admit I am exhausted but still, I don’t understand why? what is the big deal?
thank you for your help