Guards

There is no difference between microservices guards and the regular guards. The only thing you should be aware of is that instead of throwing HttpException, you should use the RpcException.

Hint The RpcException class is exposed from @nestjs/microservices package.

Binding guards

Here is an example that makes use of a method-scoped guard (class-scoped works either):

TypeScript

@UseGuards(AuthGuard)
@MessagePattern({ cmd: 'sum' })
sum(data: number[]): number {
  return (data || []).reduce((a, b) => a + b);
}
  • Guards
  • Binding guards

Support us

Nest is an MIT-licensed open source project. It can grow thanks to the support by these awesome people. If you'd like to join them, please read more here.

Principal Sponsor

Sponsors / Backers