小编Jan*_*ger的帖子

NestJs Passport jwt 未知策略

我正在尝试在我的嵌套应用程序中实施 JWT 策略进行身份验证。
我收到以下错误

未知的身份验证策略“jwt”

这是我的代码:
jwt.strategy.ts

import { Injectable } from "@nestjs/common";
import { PassportStrategy } from "@nestjs/passport";
import { Strategy } from "passport-local";
import { ExtractJwt } from "passport-jwt";
import { jwtConstants } from "./constants";

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor() {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      ignoreExpiration: false,
      secretOrKey: jwtConstants.secret,
    })
  }

  async validate(payload: any) {
    console.log(payload);
    return { userId: payload.sub, username: payload.username };
  }
}
Run Code Online (Sandbox Code Playgroud)

我的认证模块:
authentication.module.ts

import { Module } from '@nestjs/common';
import { AuthenticationService …
Run Code Online (Sandbox Code Playgroud)

jwt typescript nestjs nestjs-passport nestjs-jwt

2
推荐指数
4
解决办法
4725
查看次数

标签 统计

jwt ×1

nestjs ×1

nestjs-jwt ×1

nestjs-passport ×1

typescript ×1