cookies - NestJS 身份验证 JWT Cookie
问题描述
任何人都可以帮助我,我不知道哪里错了,但我的 jwt 身份验证不起作用,它不运行函数 validate 甚至我的请求?.cookies?.["jwt"] 存在并且总是返回状态代码 401。这是我的代码: jwt.strategy.ts:
`@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor( ) {
super({
ignoreExpiration:false,
secretOrKey: 'secret',
jwtFromRequest: ExtractJwt.fromExtractors([ (request: Request) => {
return request?.cookies?.["jwt"];
}])
})
}
async validate (payload:any) {
console.log(1);
return {mail: payload.mail };
}
}`
auth.module.ts:
`@Module({
imports:[PassportModule,
UserModule,
JwtModule.register({
secret:'secret',
signOptions:{expiresIn:'60s'}
})
],
providers: [AuthService,LocalStrategy,JwtStrategy],
exports:[AuthService]
})
export class AuthModule {}`
解决方案
推荐阅读
- python - 将 numpy random.choice 应用于具有来自 pandas df 列的概率的随机类别
- mysql - 如何将 Sequelize 关联添加到模型中
- c++ - 保存和加载未序列化的 pytorch 预训练模型
- amazon-web-services - 无法启用 AWS Amplify 管理 UI
- r - 为什么在美学映射中指定填充会改变图中的图形
- ruby-on-rails - Rails:ActiveStorage 没有保存正确的 URL
- javascript - 如何在 TextField 中显示 3 位小数,但模型应该具有 Angularjs 的原始值
- android - 如果用户从 AutoCompleteTextView 中删除,如何正确处理?
- c++ - 为什么在调用 drawBackground 时它会覆盖 setBackgroundBrush 颜色?
- c# - 'dotnet run' 不将文件复制到输出目录