我正在尝试在嵌套中使用 jwt 一切正常,但验证功能在 jwt.strategy.ts 中不起作用
这是我的 jwt.strategy.ts:
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
private userService:UserService
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey:"mysecretkey",
});
}
async validate(payload:any) {
console.log('this is payload'+payload)
它打印:这是有效载荷 undefine
用户模块
@Module({
exports:[UserService],
controllers: [UserController],
providers: [UserService,JwtStrategy],
imports : [TypeOrmModule.forFeature([UserEntity]),PassportModule.register(
{defaultStrategy:'jwt'}),
JwtModule.register({secret:'mysecretkey',signOptions:{expiresIn:3600000}})]
})
export class UserModule {}
当我在邮递员中请求时,我得到 satus:401 Unauthorized 并且在终端显示:payload undefined