1

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 ?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.