通过快速cookie会话保持登录选项



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

在github问题中,我发现cookie会话组件没有提供动态更新maxAge属性的方法。

我想知道是否有任何方法可以通过cookie-session组件实现"保持登录"功能。

在我看来,这似乎是一个每月下载8000次的组件的基本功能。

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

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

https://github.com/expressjs/session

或者req.session.cookie.maxAge将返回剩余时间以毫秒为单位,我们也可以重新分配一个新值来调整.适当地使财产到期。以下内容基本上等效

最新更新