我正在尝试在嵌套以下文档中使用 jwt
一切正常,但验证功能在 jwt.strategy.ts 中不起作用
这是我的 jwt.strategy.ts:
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { AuthService } from './auth.service';
import { JwtPayload } from './interfaces/jwt-payload.interface';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme('JWT'),
secretOrKey: 'secretKey',
});
}
async validate(payload: JwtPayload) {
console.log(payload)
// const user = await this.authService.validateUser(payload);
// if (!user) {
// throw new UnauthorizedException();
// …Run Code Online (Sandbox Code Playgroud)