相关疑难解决方法(0)

使用 JWT Passport 进行 NestJS 身份验证不起作用

我正在尝试使用 jwt-passport 和 nestjs 来设置一个非常简单的登录系统。我遵循了本教程:https : //docs.nestjs.com/techniques/authentication但我无法让它工作。我对这些东西真的很陌生,如果有人能给我指路,我将不胜感激。

我将登录名发送到服务器的方式:

    this.clientAuthService.login(this.userName, this.password).then(response => {
        this.clientAuthService.setToken(response.access_token);
        this.router.navigate(['/backend']);
    });
Run Code Online (Sandbox Code Playgroud)

我的 ClientAuthService:

export class ClientAuthService {

  constructor(private http: HttpClient, @Inject(PLATFORM_ID) private platformId) {
  }

  getToken(): string {
    if (isPlatformBrowser(this.platformId)) {
      return localStorage.getItem(TOKEN_NAME);
    } else {
      return '';
    }
  }

  setToken(token: string): void {
    if (isPlatformBrowser(this.platformId)) {
      localStorage.setItem(TOKEN_NAME, token);
    }
  }

  removeToken() {
    if (isPlatformBrowser(this.platformId)) {
      localStorage.removeItem(TOKEN_NAME);
    }
  }

  getTokenExpirationDate(token: string): Date {
    const decoded = jwt_decode(token);

    if (decoded.exp === undefined) {
      return null; …
Run Code Online (Sandbox Code Playgroud)

node.js jwt passport-local angular nestjs

3
推荐指数
1
解决办法
2979
查看次数

标签 统计

angular ×1

jwt ×1

nestjs ×1

node.js ×1

passport-local ×1