gpt4 book ai didi

node.js - 无法获取 req.user 的属性

转载 作者:太空宇宙 更新时间:2023-11-04 03:06:00 25 4
gpt4 key购买 nike

我正在使用 Passport 来验证我的项目。认证成功后,用户将被定向到“/home”。此时,请求已经有了用户对象。但是,一旦我重定向,req.user.email 就未定义。 :'(

 exports.test= function (req, res) {
console.log(req.user);
console.log(req.user.id);
console.log(req.user.email);

}

终端显示:

ModelBase {
attributes:
{ id: 18,
first_name: 'test',
last_name: 'test',
email: 'test1@gmail.com',
password: '18fa9883b74578494b578048273e66d2edbf57b6',
active: 1,
created: Mon Oct 17 2016 08:15:58 GMT+0700 (SE Asia Standard Time),
modified: Thu Nov 17 2016 10:59:00 GMT+0700 (SE Asia Standard Time),
salt: '140996000870',
Balance: 0,
ExpireDate: Mon Apr 02 2018 00:00:00 GMT+0700 (SE Asia Standard Time),
used: 0,
donate: 1 },
_previousAttributes:
{ id: 18,
first_name: 'test',
last_name: 'test',
email: 'test1@gmail.com',
password: '18fa9883b74578494b578048273e66d2edbf57b6',
active: 1,
created: Mon Oct 17 2016 08:15:58 GMT+0700 (SE Asia Standard Time),
modified: Thu Nov 17 2016 10:59:00 GMT+0700 (SE Asia Standard Time),
salt: '140996000870',
Balance: 0,
ExpireDate: Mon Apr 02 2018 00:00:00 GMT+0700 (SE Asia Standard Time),
used: 0,
donate: 1 },
changed: {},
relations: {},
cid: 'c1',
id: 18,
_knex: null }
18
undefined

最佳答案

因为在获取的 JSON 中,email 不是顶级 key 。它位于 attributes 键内。尝试使用 console.log(req.user.attributes.email);

关于node.js - 无法获取 req.user 的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40670322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com