In most of the examples on passportjs, it is recommended that the look up to the application user store be made a the deserializUser
method, like:
passport.serializeUser(function (user, done) {
done(null, user.id);
});
passport.deserializeUser(function (user, done) {
User.findById(id, function (err, user) {
done(err, user);
});
});
I traced and found that the deserializeUser
method is called on every page, whereas serializeUser
is called only once after authentication.
Wouldn't it be more efficient to query the database at serializeUser
and pass whatever details required as an object, and then deserializeUser
can pass it along to req.user
?