how to set individual session maxAge in express?

FurtiveFelon picture FurtiveFelon · Mar 15, 2012 · Viewed 33.4k times · Source

I understand that you can set the maxAge when starting up the app as follows:

connect.session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})

However, i would like to implement something along the lines of "remember me" setting, how would i go about doing that?

Thanks a lot :)

Jason

Answer

Linus Thiel picture Linus Thiel · Mar 15, 2012

You can set either expires or maxAge on the individual cookie belonging to the current user:

// This user should log in again after restarting the browser
req.session.cookie.expires = false;

// This user won't have to log in for a year
req.session.cookie.maxAge = 365 * 24 * 60 * 60 * 1000;

See connect session documentation.