[英]I cant access the req.user object data on passport js
I am using passport.js for my node/express project. 我正在为我的节点/快递项目使用passport.js 。 I have used
authenticationMiddleware()
我已经使用了
authenticationMiddleware()
I used it one of the routers. 我用它的路由器之一。
I created logs to check data the user contains. 我创建了日志来检查用户包含的数据。
console.log(req.user.username)
console.log(req.user)
console.log(req.user.last_name)
console.log(req.isAuthenticated())
It outputs: 它输出:
undefined
[ { account_no: 1,
username: 'blairwaldorf',
....,
last_name: 'Waldorf',
...,
is_activated: 1 } ]
undefined
true
Why cant I access the data but I cant access the object? 为什么我不能访问数据但我不能访问对象? Help.
救命。 Thanksss :(
谢谢:(
[ { account_no: 1,
username: 'blairwaldorf',
....,
last_name: 'Waldorf',
...,
is_activated: 1 } ]
You see this ? 你看到这个了吗?
The [..]
means its an array, and to access an element in an array, you use <array>[<index>]
. [..]
表示它是一个数组,使用<array>[<index>]
来访问数组中的元素。
so, you can access the element using req.user[<index>].username
. 因此,您可以使用
req.user[<index>].username
访问该元素。 Note that its a 0 based indexing, so to get the first element, it will be req.user[0].username
. 请注意,其基于0的索引,因此要获取第一个元素,它将是
req.user[0].username
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.