I try to run authentification with passport.js
1. I configure the sessions
app.use(session({ ...sessionConfig, ...{ cookie: { secure: isProduction }, store: sessionStore } }));
Sessions work fine
2. Passport.js middleware
app.use(passport.authenticate('session'));
3.SerializeUser and deserializeUser
/**
* Converts the user data into a simpler format to be stored in the session
*/
passport.serializeUser(function(user, cb) {
process.nextTick(function() {
cb(null, { id: user.id, username: user.username });
});
});
/**
* Transforms the session data back into a full user object to be used in subsequent requests.
*/
passport.deserializeUser(function(user, cb) {
process.nextTick(function() {
return cb(null, user);
});
});
serializeUser is called on login and the user parameter is set with user data
deserializeUser is called on page load, but ... user is empty
I coded almost the same as the official example and I can't figure out why I can't retreive user data once logged ?