这是我的功能:
exports.dashboard = function(req, res ,next) {
console.log(req.session);
var userForCheck = req.session.user_name;
console.log(user);
}
在我的控制台屏幕上,它像这样打印出req.session:
Sess {
cookie:
{ path: '/',
_expires: 2018-11-16T03:18:31.896Z,
originalMaxAge: 59999,
httpOnly: true }
user: { user_name: 'given001', password: '123' } }
但是用户变量是
undefinded
如何在没有未定义的情况下将user_name存储在userForCheck变量中?
答案 0 :(得分:1)
实际上应该是这样,
var userForCheck = req.session.user.user_name;
希望这会有所帮助!