node.js 如何在express中设置单个会话maxAge?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9714785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to set individual session maxAge in express?
提问by FurtiveFelon
I understand that you can set the maxAge when starting up the app as follows:
我了解您可以在启动应用程序时设置 maxAge,如下所示:
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
杰森
回答by Linus Gustav Larsson Thiel
You can set either expiresor maxAgeon the individual cookie belonging to the current user:
您可以在属于当前用户的单个 cookie 上设置expires或maxAge:
// 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.
请参阅连接会话文档。

