我希望有一个"保持登录"选项,例如Gmail提供的选项。 通过这种方式,用户可以决定是否希望在之前关闭之后打开新的浏览器会话时保持会话处于打开状态。
查看github问题,我看到了the cookie-session component doesn't provide a way to upate the maxAge
property dynamilly。
我想知道是否有任何方式可以实现"保持登录"具有cookie-session
组件的功能。
在我看来,正在下载80K times a month的组件的基本功能。
答案 0 :(得分:2)
// This allows you to set req.session.maxAge to let certain sessions
// have a different value than the default.
app.use(function (req, res, next) {
// here you can see whether they checked the checkbox or not, and change maxAge.
// the default should be that it expires when the browser is closed
req.sessionOptions.maxAge = req.session.maxAge || req.sessionOptions.maxAge
// or you can try to set expires to 1 day from now:
req.sessionOptions.expires = new Date(Date.now()+86400000)
// or at the end of the session:
req.sessionOptions.expires = 0
})
答案 1 :(得分:1)
如果您使用ExpressJS,会话模块有一个选项。
https://github.com/expressjs/session
或者req.session.cookie.maxAge将返回剩余时间 以毫秒为单位,我们也可以重新分配一个新值来调整 。恰当地展示财产。以下是基本上的 等效