Express会话到期与首次振动

发布于 2025-01-26 07:23:38 字数 708 浏览 1 评论 0原文

如何区分会话是否过期还是首次登录

我正在设置这样的会话,并将数据存储在Express-Mysql-Session中。

const sessionStore = new MySQLStore({}, connection);

// session
const adminSession = session({
  secret: process.env.ADMIN_SECRET,
  resave: false,
  saveUninitialized: false,
  store: sessionStore,
  name: "adminSession",
  cookie: {
    maxAge: 600000,
    secure: false,
  },
});
app.use("/api/admin", adminSession, adminRoutes);

//admin login
app.post("/api/admin/login",(req,res)=>{
    req.session.adminAuthenticated = true;
});

通过简单地检查是否有req.session.adminauthenticated,我可以知道admin是否已登录。但是我怎么知道管理员是否已经登录了,但会话过期。
对此有任何帮助。

How to differentiate whether the session expired or is it the first time logging in.

I am setting the session like this and storing the data in express-mysql-session.

const sessionStore = new MySQLStore({}, connection);

// session
const adminSession = session({
  secret: process.env.ADMIN_SECRET,
  resave: false,
  saveUninitialized: false,
  store: sessionStore,
  name: "adminSession",
  cookie: {
    maxAge: 600000,
    secure: false,
  },
});
app.use("/api/admin", adminSession, adminRoutes);

//admin login
app.post("/api/admin/login",(req,res)=>{
    req.session.adminAuthenticated = true;
});

By simply checking if there is req.session.adminAuthenticated, I can know if admin is logged in or not. But how can I know if the admin had already logged in earlier but the session expired.
Any help with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文