我有 jwt 策略:
export class JwtStrategy extends PassportStrategy(Strategy, "jwt") {
constructor() {
super({
ignoreExpiration: false,
secretOrKey: "secret",
jwtFromRequest: ExtractJwt.fromExtractors([
(request: Request) => {
let data = request.cookies['access'];
return data;
}
]),
});
}
async validate(payload: any){
return payload;
}
}
这是我的控制器:
export class AuthController {
constructor(private authService: AuthService) {}
@UseGuards(AuthGuard("jwt"))
@Get()
getPayload() {
//here I need to get the payload that was returned in jwt strategy
}
}
那么如何在控制器中获取 jwt 策略中返回的有效负载呢?