简体   繁体   中英

How to set the session timeout after log in passportjs?

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?

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.

You need to set the lifetime of the session cookie for express.session like the following example:

app.use(express.session({
             secret : 'your_cookie_secret',
             cookie:{_expires : 60000000}, // time im ms
             })
        ); 

For testing I recommend a shorter expires time.

Error: Most middleware (like session) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware .

Got this using latest node toolchain... so this may not work anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM