小编San*_*ang的帖子

如何在 Nestjs 中刷新令牌

import { ExtractJwt, Strategy } from 'passport-jwt';
import { AuthService } from './auth.service';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtPayload } from './model/jwt-payload.model';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
  constructor(private readonly authService: AuthService) {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      secretOrKey: 'secretKey',
    });
  }

  async validate(payload: JwtPayload) {
    const user = await this.authService.validateUser(payload);
    if (!user) {
      throw new UnauthorizedException();
    }
    return true;
  }
}
Run Code Online (Sandbox Code Playgroud)

令牌是从请求中提取的PassportStrategy。我不知道如何在令牌过期或无效时捕获错误。我的目的是如果因为令牌过期而出现错误,我需要刷新令牌。否则做别的事情。

javascript node.js typescript passport.js nestjs

21
推荐指数
2
解决办法
2万
查看次数

如何在蚂蚁设计或材质 UI 中使用 react-hook-form

我正在尝试使用 react-hook-form 库来验证表单。当我使用 ant design 或 material UI 渲染视图时,它无法正常工作。

<Input name="firstName" ref={register({ required: true })} />
  {errors.firstName && 'First name is required'}
Run Code Online (Sandbox Code Playgroud)

发生了一些警告:"Missing name at.....".

reactjs material-ui antd react-hook-form

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