【问题标题】:How can I modify the expiration timeout for the session如何修改会话的过期超时
【发布时间】:2019-08-06 07:06:57
【问题描述】:

我需要修改过期超时时间。
我正在使用护照进行登录身份验证和会话存储。

这里是mongodb图集截图:

【问题讨论】:

标签: mongodb express passport.js session-cookies


【解决方案1】:

我认为您需要使用express-session 设置/修改您的cookie 过期时间,并使用cookie.maxAge 属性设置maxAge 也就是您的cookie 的过期时间。

试试这个:

// you need to require express-session for it to work. 
var expressSession = require(express-session);

app.use(
    expressSession({
        secret: "your_Secret",
        resave: false,
        saveUninitialized: true,
        cookie : { maxAge : 3600000 } //1 hour (time is in milli seconds here)
    })
);

//initialize passport here

Passport 需要初始化会话才能使其会话工作,我想你一定是这样做的,只需在其中添加 cookie 字段和 maxAge 即可。

希望对你有所帮助。

【讨论】:

  • 你能告诉我你是如何初始化护照和你的 app.js/server.js 代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-01
  • 2020-04-25
  • 2016-10-26
  • 2011-11-18
  • 2018-12-14
  • 1970-01-01
相关资源
最近更新 更多