nestjs-components icon indicating copy to clipboard operation
nestjs-components copied to clipboard

google pub sub client cannot pass data from auth guard to controller

Open michaelanggriawan opened this issue 3 years ago • 2 comments

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();
        }),
      );
  }

michaelanggriawan avatar Jun 21 '22 18:06 michaelanggriawan

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 ?

michaelanggriawan avatar Jun 27 '22 04:06 michaelanggriawan

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

ccoeurderoy avatar Aug 31 '22 08:08 ccoeurderoy