简体   繁体   English

登录passportjs后如何设置会话超时?

[英]How to set the session timeout after log in passportjs?

I want to set a session timeout after log in using passportjs. 我想在使用passportjs登录后设置会话超时。 How to set the maxAge for the session using passportjs. 如何使用passportjs为会话设置maxAge。 What is the default max age for the session that passportjs provide? passportjs提供的会话的默认最长期限是多少?

That is handled via Connect's session middleware, so for example: 这是通过Connect的会话中间件处理的,例如:

.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: 您需要为express.session设置会话cookie的生命周期,如下例所示:

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. 错误:大多数中间件(如会话)不再与Express捆绑在一起,必须单独安装。 Please see https://github.com/senchalabs/connect#middleware . 请参阅https://github.com/senchalabs/connect#middleware

Got this using latest node toolchain... so this may not work anymore. 使用最新的节点工具链得到这个...所以这可能不再起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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