【问题标题】:How to session logout automatically after 10 minutes of inactivity in expressjs?如何在 expressjs 中闲置 10 分钟后自动注销会话?
【发布时间】:2020-12-27 22:19:06
【问题描述】:

我在 app.js 中使用此代码进行会话

app.use(cookieParser());
app.use(session({
    secret: config.sessionKey,
    resave: false,
    saveUninitialized: true,
    maxAge: 600*1000

}));

我刚读到某处我需要启用 maxAge 作为时间限制。这是正确的吗?我做对了吗?

【问题讨论】:

    标签: node.js express session cookies logout


    【解决方案1】:

    在cookie中设置maxAge属性-

    app.use(session({
        secret: config.sessionKey,
        resave: false,
        saveUninitialized: true,
        cookie: {
            maxAge: 600 * 1000
        }
    }));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多