Search code examples
expresspassport.jsexpress-session

How to manually reload Passport express-session store


I have web and mobile clients and an external authentication server.

I want to make a successful request to passport.isAuthenticated() behind the /loggedIn route by supplying a cached session object from the client.

I need to reload the session before the call to req.isAuthenticated(). This is necessary because the server's req/store is not properly populated when the request from the client hits the API endpoint -- we need to repopulate REQ.

I have done this before, and I remember a nuance where it was required to load the passport/express session fields individually.


Solution

  • The following code is required to reload server.req with the client's passport session. The session can not be reassigned with one line of code, and must instead of separated like this:

    req.session.cookie = req.body.cookie;
    req.session.passport = req.body.passport;
    req.user = req.body.user;