typescript - 当令牌添加到标题不间断查询显示时
问题描述
当我使用 graphql 游乐场在我的 nestjs 应用程序中将令牌添加到标题时,它会在控制台控制台中不断重复选择查询
这是我的 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,
});
}
}
解决方案
推荐阅读
- java - 如何通过 jline3 在每一行添加字符串?
- c++ - 如何检查嵌套成员是否存在 Rapidjson
- javascript - react-native 和 react-dom 的主要区别是什么
- ios - Xamarin ITMS-90809 错误已弃用 Api 使用
- c# - 在不知道类型的情况下构造泛型类
- reactjs - 反应路由器:在除首页外的所有页面上使用菜单
- reactjs - 无法在本机反应中使用 webrtc
- typescript - 如何像这样修复 TypeScript 错误(ts:2740)
- c# - asp.net core 3.1 将 autofac 与 finbuckle 集成
- getstream-io - 当用户取消关注 GetStream 上的提要时,如何处理“关注”活动?