saveUninitialized doesn't work with PassportJS
See original GitHub issueSessions are always saved, even when saveUninitialized
is set to false
.
I’ve done a little bit of investigation, and I think I have identified the issue. Looks like it is in lines 420 - 429. When it hashes the “original session” it does so session without the id
being set on it. So when it hashes it again at the end of the request the shouldSave
returns true
because the session now has the id
set.
If this is indeed the problem, one approach might be replacing store.createSession(req, sess);
with sess = store.createSession(req, sess);
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Session IDs don't persist unless passport.js is initialized
I have a simple, generic express app. It logs the req.sessionID whenever a certain route is hit. I would expect that refreshing the...
Read more >Documentation: Sessions - Passport.js
To maintain a login session, Passport serializes and deserializes user information to and from the session. The information that is stored is determined...
Read more >Express session middleware
saveUninitialized. Forces a session that is “uninitialized” to be saved to the store. A session is uninitialized when it is new but not...
Read more >How to use the passport.session function in passport - Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >User Authentication in Web Apps (Passport.js, Node, Express)
You will learn how to use Passport.js in a Node / Express app. ... Intro to Public Key Cryptography ⌨️ (3:34:31) How do...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I figured it out… Somehow was using an older version of passportjs (0.2.2). Updated to 0.3.2, which fixed this issue. The old version was adding an empty passport object to the session, which caused the dirty check to fail, and this created the session. Sorry for the false alarm and thanks for your help.
The moral of the story, for other who experience this problem in the future, is to make sure that you don’t have some middleware that is adding things to the req.session object unnecessarily.
@brendonparker Sir, Can I chat with you, I have few doubts about sessions that are troubling me.