如果我像这样在会话中存储一个对象:
user.name = "Kelvin"; // user is an object pass by "mongoose" findOne's callback.
req.session.user = user;
console.log(req.session.user.name); // Kelvin
之后,我在其他快递路线中访问“用户”:
app.get("/somepath", function(req, resp) {
console.log(req.session.user.name); // undefined
});
我想知道为什么 req.session.user.name 除了我设置的函数之外没有定义?