我想使用会话值
但我不知道如何获取会话值。
我尝试输入console.log
var aaa = req.session;
var bbb = req.session.passport;
var ccc = req.session.passport.user;
aaa,bbb,ccc是可以获得的价值。 结果是(控制台)
//aaa
passport : { user:[ [Object] ] } }
//bbb
{ user:
[{ no : 1, id : aaa, pw : 123 }]
//ccc
[{ no : 1, id : aaa, pw : 123 }]
然后,我不能得到没有,id,pw值......
我试过这样。
然后,我不能得到没有,id,pw值......
我试过这样。
var ddd = req.session.passport.user[0].value;
它不起作用。
这是我的代码。 有没有人如何解决它。
passport.use('login', new LocalStrategy({
usernameField : 'email',
passwordField : 'pw',
passReqToCallback : true
},function(req, email, pw, done) { mysql.select('select * from MYTABLE where email ="'+email+'" and pwd = "'+pw+'"', function (err, data){
// below code is working.
console.log(data[0].no);
if(data.length < 1){
console.log('fail');
return done(null, false);
}else {
console.log('success');
console.log(data);
return done(null, data);
}
if(err){
res.redirect('back');
}
});
}
));
router.get('/test', function(req, res, next) {
//console.log("123123");
var aaa = req.session;
var bbb = req.session.passport;
var ccc = req.session.passport.user;
console.log(aaa);
console.log(bbb);
console.log(ccc);
console.log("++++");
//var ddd = req.session.passport.user[0].value;
//var eee = req.session.passport.user.value;
//var fff = req.session.passport.user.no.value;
// ddd eee fff isn't work.
res.render('front/login_test', {});
});
答案 0 :(得分:1)
用户对象中没有任何名为“value”的键。试试:
var no = req.session.passport.user[0].no;
var id = req.session.passport.user[0].id;
var password = req.session.passport.user[0].pw;