我有文档示例中的 JwtStrategy 类(https://docs.nestjs.com/techniques/authentication):
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
private readonly authService: AuthService,
private readonly configService: ConfigService,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: this.configService.getSecretKey,
});
}
// ...
}
当我尝试访问时this
在调用 super() 之前我收到一个错误。但我仍然想使用 configService 来获取密钥。
我知道我可以使用 env var 来做到这一点,但在我看来,服务方法是更清晰的解决方案。
我如何使用 configService 或者从中获取值并传递给 super() 调用?谢谢。
只需删除this.
, 看这里:
secretOrKey: configService.getSecretKey
它将起作用,因为configService
已作为参数传递。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)