小编jie*_*jie的帖子

Nestjs:验证功能不适用于 jwt

我正在尝试在嵌套以下文档中使用 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)

node.js jwt typescript nestjs

2
推荐指数
1
解决办法
3398
查看次数

标签 统计

jwt ×1

nestjs ×1

node.js ×1

typescript ×1