保持login选项与cookie会话快递

我想要有一个“保持login状态”的选项,例如Gmail提供的选项。 通过这种方式,用户可以决定是否在先前closures之后打开新的浏览器会话时保持会话打开状态。

看着github的问题,我看到cookie会话组件没有提供一种方法来提升maxAge属性dynamilly 。

我想知道如果有什么办法来实现cookie-session组件的“保持login”function。

在我看来, 每月下载80K次的组件的基本function。

如果您使用ExpressJS,会话模块有一个选项。

https://github.com/expressjs/session

或者,req.session.cookie.maxAge将返回剩余的时间(以毫秒为单位),我们也可以重新分配一个新值来适当调整.expires属性。 以下基本相同

 // 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 })