0

when i console.log the req in the middleware there is no user{} in the req

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

but when i console.log the req on an endpoint there is one

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

so when does nestjs exactly add the user{} that i catch it and manipulate bevor the controller

raho
  • 1

1 Answers1

0

user is usually added by passport, which most times is added using @nestjs/passport and the AuthGuard() guard

Jay McDoniel
  • 57,339
  • 7
  • 135
  • 147