【问题标题】:when does nestjs add the user object to the reqestnext js 什么时候将用户对象添加到请求中
【发布时间】:2023-03-19 20:29:01
【问题描述】:

当我 console.log 中间件中的 req 时,req 中没有用户{}

@Injectable()
export class MyMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    console.log(req);
    next();
  }
}

但是当我 console.log 端点上的请求时,有一个

 @Get('me')
  async getMe(@Req() req: Request) {
    console.log(req)
    const res = await this.operatorService.findOneAndPopulate(
      (req['user'] as any)._id,
    );
    return res;
  }

那么,nestjs 什么时候准确地添加我捕获它并在控制器之前操作的用户{}

【问题讨论】:

标签: http nestjs req


【解决方案1】:

user通常由护照添加,大多数情况下使用@nestjs/passportAuthGuard()保护添加

【讨论】:

    猜你喜欢
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2014-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多