首页 > 解决方案 > req.session 不在另一条路线上工作

问题描述

我试图在 express 中使用会话,但它不能正常工作

app.get("/mod", async function (req, res) {
     var sess = req.session;
      console.log(sess)
})

输出是

Session {
cookie: { path: '/', _expires: null, originalMaxAge: null, httpOnly: true }, 
uid: '1234123123',
utag: 'Tag_etc',
uav: 'other stuff'
}

但是如果我使用

     app.get("/approve", async function (req, res) {
            var sess = req.session;
            console.log(sess)
})

输出是

Session {
    cookie: { path: '/', _expires: null, originalMaxAge: null, httpOnly: true }
}

没有我需要的其他东西。知道为什么会这样吗?

谢谢你的帮助:D

标签: node.jsexpresssession

解决方案


尝试发送响应:res.send("hello") 这将正确终止连接并写入会话


推荐阅读