title: NestJs - Unable to get user auth response on Bearer Token
body: <p>I'm using NestJs as framework and jwt for auth. I tried to login to the endpoint using user credentials, then I receive a jwt token as a response. After that, I use that token (bearer token) to get access to all the users info(code below) but I'm getting the following error:</p>
  <pre><code>Error
  [Nest] 17189   - 03/15/2021, 12:52:59 PM   [ExceptionsHandler] this.validate is not a function +47159ms
  TypeError: this.validate is not a function
      at JwtStrategy.&lt;anonymous&gt; (/Users/axels18m/Desktop/Work/Testing/nest-twitter-project/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:19:55)
      at Generator.next (&lt;anonymous&gt;)
      at /Users/axels18m/Desktop/Work/Testing/nest-twitter-project/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:8:71
      at new Promise (&lt;anonymous&gt;)
      at __awaiter (/Users/axels18m/Desktop/Work/Testing/nest-twitter-project/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:4:12)
      at JwtStrategy.callback [as _verify] (/Users/axels18m/Desktop/Work/Testing/nest-twitter-project/node_modules/@nestjs/passport/dist/passport/passport.strategy.js:16:45)
      at /Users/axels18m/Desktop/Work/Testing/nest-twitter-project/node_modules/passport-jwt/lib/strategy.js:123:34
      at /Users/axels18m/Desktop/Work/Testing/nest-twitter-project/node_modules/jsonwebtoken/verify.js:223:12
      at getSecret (/Users/axels18m/Desktop/Work/Testing/nest-twitter-project/node_modules/jsonwebtoken/verify.js:90:14)
      at Object.module.exports [as verify] (/Users/axels18m/Desktop/Work/Testing/nest-twitter-project/node_modules/jsonwebtoken/verify.js:94:10)
  </code></pre>
  <p>Here is the endpoint where the error is raised (user.controller.ts)</p>
  <pre><code>@Controller('user')
  export class UserController 
  {
      constructor(
          private userService: UserService
      ) {}
  
      @hasRoles('admin')
      @UseGuards(JwtAuthGuard, RolesGuard)
      @Get()
      getAll(): Observable&lt;User[]&gt;
      { 
          return this.userService.getAll(); 
      }
  }
  </code></pre>
  <ul>
  <li>jwt-strategy.ts file</li>
  </ul>
  <pre><code>@Injectable()
  export class JwtStrategy extends PassportStrategy(Strategy)
  {
      constructor(private configService: ConfigService)
      {
          super({
              jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
              ignoreExpiration: false,
              secretOrKey: configService.get('JWT_SECRET')
          });
      }
  
      async validator(payload: any)
      {
          return { 'user': payload.user , 'username': payload.username };
      }
  }
  </code></pre>
  <p>Steps for getAll users:</p>
  <ul>
  <li>login (returns a jwt token to use as bearer token)</li>
  </ul>
  <pre><code>@Post('login')
    login(@Body() user: User): Observable&lt;Object&gt;
    {
      return this.userService.login(user).pipe(
        map((jwt: string) =&gt; { return { access_token: jwt} })
      )
    }
  </code></pre>
  <ul>
  <li>After adding the bearer token and send it to getAll users method (this if for getting access to get all users info, without the barear token, you'll get an Unauthorized 401 error), the AuthGuard is fired and shows the above error. I already tried this:
  <code>@UserGuards(AuthGuard('jwt'), RolesGuard)</code> instead of <code>@UseGuards(JwtAuthGuard, RolesGuard)</code></li>
  </ul>