question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

saveUninitialized doesn't work with PassportJS

See original GitHub issue

Sessions 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:closed
  • Created 7 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
brendonparkercommented, May 18, 2016

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.

0reactions
meetDevelopercommented, Jan 2, 2018

@brendonparker Sir, Can I chat with you, I have few doubts about sessions that are troubling me.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found