1

I try add configService to JwtStrategy:

  constructor(readonly configService: ConfigService) {
    super({
      //...
      secretOrKey: this.configService.get('SECRET_KEY'),
    });
  }

I'm using this instruction. But TS return me error:

'super' must be called before accessing 'this' in the constructor of a derived class.

When I remove this (like in this answer), then Nest return another error:

Nest can't resolve dependencies of the JwtStrategy (?). Please make sure that the argument ConfigService at index [0] is available in the AuthModule context.

Progman
  • 16,827
  • 6
  • 33
  • 48
michal
  • 1,534
  • 5
  • 28
  • 62

1 Answers1

1

I fix it by adding ConfigService to providers in auth.module.ts file:

@Module({
  controllers: [AuthController],
  providers: [AuthService, JwtStrategy, ConfigService],
  exports: [JwtStrategy],
})

I had to remove private from constructor and remove this from configService.

michal
  • 1,534
  • 5
  • 28
  • 62