16

我想要一个“保持登录”选项,例如 Gmail 提供的选项。这样,用户可以决定是否要在之前关闭浏览器会话后打开新的浏览器会话时保持会话打开。

在查看 github 问题时,我看到cookie-session 组件没有提供更新maxAge属性 dynamilly的方法。

我想知道是否有任何方法可以使用cookie-session组件实现“保持登录”功能。

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

4

2 回答 2

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
})
于 2016-01-19T20:26:58.590 回答
1

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

https://github.com/expressjs/session

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

于 2016-01-20T05:51:11.943 回答