In the example from the NestJS documentation (https://docs.nestjs.com/techniques/authentication), I have the JwtStrategy class:
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
private readonly authService: AuthService,
private readonly configService: ConfigService,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: this.configService.getSecretKey,
});
}
// ...
}
When attempting to access this
before calling super(), an error is encountered. However, it is still desired to utilize the configService for obtaining the secret key.
Although utilizing an environment variable is a viable option, using the service approach seems more clear to me as a solution.
Is there a way to use the configService or retrieve a value from it and pass it to the super() call? Thank you.