Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 当令牌添加到标头时,不间断查询显示_Typescript_Graphql_Nestjs - Fatal编程技术网

Typescript 当令牌添加到标头时,不间断查询显示

Typescript 当令牌添加到标头时,不间断查询显示,typescript,graphql,nestjs,Typescript,Graphql,Nestjs,当我使用graphql将令牌添加到nestjs应用程序的头中时,它会不断重复控制台中的select查询 这是我的jwt中间件 应用程序模块 export class JwtMiddleware implements NestMiddleware { constructor( private readonly jwtService: JwtService, private readonly userService: UsersService, ) {} async us

当我使用graphql将令牌添加到nestjs应用程序的头中时,它会不断重复控制台中的select查询

这是我的jwt中间件

应用程序模块

export class JwtMiddleware implements NestMiddleware {
  constructor(
    private readonly jwtService: JwtService,
    private readonly userService: UsersService,
  ) {}
  async use(req: Request, res: Response, next: NextFunction) {
    if ('x-jwt' in req.headers) {
      const token = req.headers['x-jwt'];
      try {
        const decoded = this.jwtService.verify(token.toString());
        if (typeof decoded === 'object' && decoded.hasOwnProperty('id')) {
          const user = await this.userService.findById(decoded['id']);
          req['user'] = user;
        }
      } catch (e) {}
    }
    next();
  }
}
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(JwtMiddleware).forRoutes({
      path: '/graphql',
      method: RequestMethod.POST,
    });
  }
}