繁体   English   中英

如何在 Nestjs 中获取登录用户的属性

[英]How to get properties of Loggedin user in Nestjs

我可以使用这个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;
}
}

但我无法访问当前用户的属性

我试过loggedin.firstname但我得到Property 'firstname' does not exist on type 'User'

我怎样才能解决这个问题?

我解决问题,

export class PostService {
    constructor(
        @Inject(REQUEST) private request: any,
        private userService: UserService
    ) { }

async GetPosts(){
     const loggedin = this.request.user

}
}

我将请求类型更改为any类型并像这样解构它

  const { _id, firstname } = this.request.user

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM