在快递中使用cookie会话保持登录选项 [英] Stay signed in option with cookie-session in express

查看:227
本文介绍了在快递中使用cookie会话保持登录选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有一个保持登录选项,如Gmail提供的选项。
这样,用户可以决定,如果他们希望在之前关闭新的浏览器会话时保持会话状态。

I would like to have a "Stay signed in" option such as the one provided by Gmail. This way, the user can decide if they want to keep the session open upon opening a new browser session after previously closing it.

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

Looking into the github issues I saw the cookie-session component doesn't provide a way to upate the maxAge property dynamilly.

我想知道,如果有任何方法实现保持登录功能与 cookie会话组件。

I'm wondering then if there's any way at all to achieve the "Stay signed in" feature with the cookie-session component.

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

It seems to me a basic feature for a component which is being downloaded 80K times a month.

推荐答案

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

这篇关于在快递中使用cookie会话保持登录选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆