jaredhanson / passport

Simple, unobtrusive authentication for Node.js.
https://www.passportjs.org?utm_source=github&utm_medium=referral&utm_campaign=passport&utm_content=about
MIT License
22.97k stars 1.24k forks source link

How to set the session timeout in passportjs? #158

Closed jetsonjohn closed 11 years ago

jetsonjohn commented 11 years ago

I want to set a session timeout after log in using passportjs. How to set the maxAge for the session using passportjs. What is the default max age for the session that passportjs provide?

jaredhanson commented 11 years ago

That is handled via Connect's session middleware, so for example:

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

The documentation has other useful bits that are worth reading for understanding session handling.

vebtopalli commented 5 years ago
app.use(function (req, res, next) {
  req.sessionOptions.maxAge = 24 * 60 * 60 * 1000 // 24 hours,
  next()
})

Refer to #Per-user sticky max age https://github.com/expressjs/cookie-session