Session: So what exactly saveUninitialized is for?

Created on 6 Jun 2015  路  3Comments  路  Source: expressjs/session

The thing that I got is that when saveUninitialized is false then it's not storing session in store. So then how to create session manually if it's not in req.session?

question

Most helpful comment

@yolapop saveUninitialized means if you have not added anything to the "session" there is no session created (no cookie is sent to the user). ie: A user goes to your blog to read something they are just there to read something and leave they don't need a session saveUninitialized = false will not make a session for them. If they login and your app runs req.session.username = <their username> their session is created and a cookie is sent to them.

  • This is great for the EU sites that need to abide by the cookie law that requires them to ask permission _before_ sending the user a cookie.
  • It also is great if you have limited space & a lot of your traffic will not need sessions.

All 3 comments

@yolapop saveUninitialized means if you have not added anything to the "session" there is no session created (no cookie is sent to the user). ie: A user goes to your blog to read something they are just there to read something and leave they don't need a session saveUninitialized = false will not make a session for them. If they login and your app runs req.session.username = <their username> their session is created and a cookie is sent to them.

  • This is great for the EU sites that need to abide by the cookie law that requires them to ask permission _before_ sending the user a cookie.
  • It also is great if you have limited space & a lot of your traffic will not need sessions.

@gabeio thanks for the explanation, but when I used saveUninitialized = false, I couldn't set req.session.username = <their username> because req.session was undefined. I'm confused about how to create session manually

Wait, sorry I just remembered, it's resolved. req.session was not undefined.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simoami picture simoami  路  27Comments

nhitchins picture nhitchins  路  20Comments

aheyer picture aheyer  路  15Comments

antishok picture antishok  路  27Comments

gk0us picture gk0us  路  18Comments