简体   繁体   English

如何使用Express-Session存储会话中的数据

[英]How to store data from session using Express-session

Here is my function: 这是我的功能:

exports.dashboard = function(req, res ,next) {


console.log(req.session);
var userForCheck =  req.session.user_name;
console.log(user);
}

in my console screen it's printed out req.session like this : 在我的控制台屏幕上,它像这样打印出了req.session:

Sess {
 cookie:
  { path: '/',
   _expires: 2018-11-16T03:18:31.896Z,
   originalMaxAge: 59999,
  httpOnly: true }
user: { user_name: 'given001', password: '123' } }

but the user variable is 但是用户变量是

 undefinded

how can i store user_name in userForCheck variable without undefined? 如何在没有未定义的情况下将user_name存储在userForCheck变量中?

Actually it should be like, 其实应该是这样

var userForCheck =  req.session.user.user_name;

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM