我正在使用护照。一切都好。我有一个登录会话,可以到达req.user对象并将其记录下来,但是当我尝试到达req.user.name时,它将返回未定义的状态。
我尝试记录req.user.email,这很好。
router.get('/profile', isLoggedIn , (req, res, next) => {
agentName = req.user.name;
console.log(`agents name is: ${agentName}`);
Customer.find({agent: agentName}, (err, customers) => {
if (err) {
return res.write('error finding customers')
}
console.log('this is the req.user.name: ' + req.user.name);
console.log('this is the req.user.email: ' + req.user.email);
console.log('this is the req. user: ' + req.user);
console.log(customers);
res.render('user/profile', {title: res, customers: customers});
return customers
})
})
//我正在使用上面的console.log向您显示正在返回什么数据
下面是我的控制台
POST /user/signin 302 222.459 ms - 70
agents name is: undefined
this is the req.user.name: undefined
this is the req.user.email: test3@gmail.com
this is the req.user: { _id: 5cfce554964817268800313e,
name: 'agent1',
email: 'test3@gmail.com',
password:
'$2a$05$MMZtM.ggdi0XGdub/wijjuUv6KePf5KC0SjSnlZAc94FcuIoa4nZm',
__v: 0 }
[]
如您所见,对象本身在那里。我可以到达其中的电子邮件部分,但不能到达名称。有什么想法吗?