Developing a Secure API with NestJS

Hi @dan-auth0 Somehow my Auth0Strategy doesn’t do anything. Nothing return in validate callback function. According to your documentation I suppose to see payload.


@Module({
  imports: [
    DatabaseModule.forFeature([UserEntity, UserTeam]),
    PassportModule.register({
      defaultStrategy: 'jwt',
    }),
    JwtModule,
  ],
  providers: [ConfigService, Auth0Strategy, AppResolver, AppService],
  exports: [AppService, PassportModule],
})

@Injectable()
export class Auth0Strategy extends PassportStrategy(Strategy, 'jwt') {
  constructor(
    private configService: ConfigService,
    private appService: AppService
  ) {
    super({
      secretOrKeyProvider: passportJwtSecret({
        cache: true,
        rateLimit: true,
        jwksRequestsPerMinute: 5,
        jwksUri: `https://${configService.get(
          'NX_AUTH0_DOMAIN'
        )}/.well-known/jwks.json`,
      }),
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      ignoreExpiration: false,
      audience: configService.get('NX_AUTH0_AUDIENCE'),
      issuer: configService.get('NX_AUTH0_ISSUER_URL'),
      algorithms: ['RS256'],
    });
  }

  validate(payload: any) {
 // Nothing return here.
    return this.appService.findOneByOrFail({ email: payload.email });
  }
}

1 Like