docs-nestjs-com-websockets-guards...
docs-nestjs-com-websockets-guards...
Guards
There is no fundamental difference between web sockets guards and regular
HTTP application guards. The only difference is that instead of throwing
HttpException , you should use WsException .
Build your website for
just $3.88/mth. More
value and performance
HINT with Namecheap.
ADS VIA CARBON
The WsException class is exposed from @nestjs/websockets package.
Binding guards
The following example uses a method-scoped guard. Just as with HTTP based applications, you can
also use gateway-scoped guards (i.e., prefix the gateway class with a @UseGuards() decorator).
JS
@UseGuards(AuthGuard) content_copy
@SubscribeMessage('events')
handleEvent(client: Client, data: unknown): WsResponse<unknown> {
const event = 'events';
return { event, data };
}
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 Sponsors
Sponsors / Partners
Become a sponsor
Email address..