nestjs-api-tutorial icon indicating copy to clipboard operation
nestjs-api-tutorial copied to clipboard

Code in the jwt.strategy.ts file is not working properly

Open amuthansakthivel opened this issue 2 years ago • 0 comments

I am creating this issue just in case if someone is following the nodejs tutorial on freecodecamp and facing issue while implementing the JWT strategy.

https://github.com/mikenicholson/passport-jwt/issues/153


export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor(private configService: ConfigService) {
    super({
      secretOrKey: configService.get('JWT_SECRET'),
      jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme('Bearer'), //instead of ExtractJwt.fromAuthHeaderAsBearerToken()
      ignoreExpiration: true,
    });
  }

  validate(payload: any) {
    console.log(payload);
    return payload;
  }

While calling the request you can normally pass Authorization header as Bearer ${token}

amuthansakthivel avatar Jan 04 '24 04:01 amuthansakthivel