Express session vs. PassportJS session Express session vs. PassportJS session express express

Express session vs. PassportJS session


No, they are two separate things and they do not conflict which other. Moreover, passport.session has to be used after express.session in order to work properly.

express.session middleware is used to retrieve user session from a datastore (like Redis). We can find the session object because the session Id is stored in the cookie, which is provided to the server with every request.

Then, the purpose of passport.session middleware is to deserialize user object from session using passport.deserializeUser function (that you define in your passport configuration). When user first authenticates itself, its user object is serialized and stored in the session. On each following request, the middleware deserialize the user and populates req.user object.

Check Passpot Configure Guide and this SO answer: What does passport.session() middleware do? for more information.