[英]How to get properties of Loggedin user in Nestjs
I am able to get the current logged in user object in the service.ts with this const loggedin = this.request.user
我可以使用这个const loggedin = this.request.user
export class PostService {
constructor(
@Inject(REQUEST) private request: Request,
private userService: UserService
) { }
async GetPosts(){
const loggedin = this.request.user
loggedin.firstname;
}
}
But I cant access the properites of the current user但我无法访问当前用户的属性
I tried loggedin.firstname
but I got Property 'firstname' does not exist on type 'User'
我试过loggedin.firstname
但我得到Property 'firstname' does not exist on type 'User'
How can I fix this?我怎样才能解决这个问题?
I solve the issue,我解决问题,
export class PostService {
constructor(
@Inject(REQUEST) private request: any,
private userService: UserService
) { }
async GetPosts(){
const loggedin = this.request.user
}
}
I changed the request type to any
and I destructure it like this我将请求类型更改为any
类型并像这样解构它
const { _id, firstname } = this.request.user
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.