nestjs-components
nestjs-components copied to clipboard
google pub sub client cannot pass data from auth guard to controller
I was trying to implement auth guard on the microservices, but on the auth guard class, we need to send the data via this.client.send which needs to be using MessagePattern, but I saw currently we don't handle this feature yet.
I might need help to fix the above problem.
this is my auth guard class:
constructor(@Inject('PUBSUB_CLIENT') private client: ClientProxy) {}
canActivate(
context: ExecutionContext,
): boolean | Promise<boolean> | Observable<boolean> {
const authentication = this.getAuthentication(context);
return this.client
.send('authentication-topic', {
Authentication: authentication,
})
.pipe(
tap((res) => {
this.addUser(res, context);
}),
catchError(() => {
throw new UnauthorizedException();
}),
);
}
Hello @ccoeurderoy, is there a way to implement event-based-messaging for pub sub, sorry I'm new at nestjs, if possible can u give me a hint to implement this inside this package ?
Hey @michaelanggriawan, sorry for the late reply! To send message to a topic, you must use the client.emit method, the send method is not handled