NestJS 全局身份验证全局守卫与 RabbitMQ 订阅者发生冲突
我正在使用 @golevelup/nestjs-rabbitmq 来处理来自队列的 RabbitMQ 消息,全局防护正在拦截来自队列的请求。有什么办法可以阻止全局警卫收到这些请求吗?
Auth Guard
@Injectable()
export default class GqlAuthGuard extends AuthGuard(AuthStrategy.Jwt) {
constructor(private reflector: Reflector) {
super();
}
getRequest(context: ExecutionContext) {
const ctx = GqlExecutionContext.create(context);
return ctx.getContext();
}
canActivate(context: ExecutionContext) {
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
context.getHandler(),
context.getClass(),
]);
if (isPublic) {
return true;
}
return super.canActivate(context);
}
}
RabbitMQ Subscriber
@SubscribeToEvent({
queue: Topic.SendSurvey,
})
async handler({ surveyId, schedulingEventId }: HandlerParams) {
this.logger.info('Handling message', surveyId, schedulingEventId);
this.surveysService.dispatch(surveyId, schedulingEventId);
}
我遇到的错误
[22-03-24 02:52:31] [error] [app] TypeError: Cannot read properties of undefined (reading 'req') {"0":"MotivatoExceptionsHandler"}
[22-03-24 02:52:31] [error] [app] TypeError: Cannot read properties of undefined (reading 'req') {"0":"MotivatoExceptionsHandler"}
[22-03-24 02:52:31] [error] [app] TypeError: Cannot read properties of undefined (reading 'req') {"0":"MotivatoExceptionsHandler"}
[22-03-24 02:52:31] [error] [app] TypeError: Cannot read properties of undefined (reading 'req') {"0":"MotivatoExceptionsHandler"}
我尝试更改 getRequest
但它不起作用
I'm using @golevelup/nestjs-rabbitmq
to handle RabbitMQ messages from a queue, the global guard is intercepting the requests from the queue. Is there any way to prevent the global guard to get these requests?
Auth guard
@Injectable()
export default class GqlAuthGuard extends AuthGuard(AuthStrategy.Jwt) {
constructor(private reflector: Reflector) {
super();
}
getRequest(context: ExecutionContext) {
const ctx = GqlExecutionContext.create(context);
return ctx.getContext();
}
canActivate(context: ExecutionContext) {
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
context.getHandler(),
context.getClass(),
]);
if (isPublic) {
return true;
}
return super.canActivate(context);
}
}
RabbitMQ Subscriber
@SubscribeToEvent({
queue: Topic.SendSurvey,
})
async handler({ surveyId, schedulingEventId }: HandlerParams) {
this.logger.info('Handling message', surveyId, schedulingEventId);
this.surveysService.dispatch(surveyId, schedulingEventId);
}
The error I'm getting
[22-03-24 02:52:31] [error] [app] TypeError: Cannot read properties of undefined (reading 'req') {"0":"MotivatoExceptionsHandler"}
[22-03-24 02:52:31] [error] [app] TypeError: Cannot read properties of undefined (reading 'req') {"0":"MotivatoExceptionsHandler"}
[22-03-24 02:52:31] [error] [app] TypeError: Cannot read properties of undefined (reading 'req') {"0":"MotivatoExceptionsHandler"}
[22-03-24 02:52:31] [error] [app] TypeError: Cannot read properties of undefined (reading 'req') {"0":"MotivatoExceptionsHandler"}
I tried changing the getRequest
but it didn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以这种方式添加时有效
It works when adding in this way