保持登录选项与快递cookie会话

Alv*_*aro 16 node.js express cookie-session

我希望有一个"保持登录状态"选项,例如Gmail提供的选项.这样,用户可以决定他们是否希望在先前关闭它之后打开新的浏览器会话时保持会话打开.

在查看github问题时,我看到cookie-session组件没有提供一种方法来提升动态maxAge属性.

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

在我看来,一个组件的基本功能是每月下载80K次.

Gav*_*iel 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
})
Run Code Online (Sandbox Code Playgroud)