0% found this document useful (0 votes)
6 views

docs-nestjs-com-websockets-guards...

Web socket guards in NestJS function similarly to regular HTTP application guards, with the key difference being the use of WsException instead of HttpException. Method-scoped and gateway-scoped guards can be implemented using the @UseGuards() decorator. The document also highlights the support for the NestJS project and encourages users to subscribe for updates.

Uploaded by

dharmendra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

docs-nestjs-com-websockets-guards...

Web socket guards in NestJS function similarly to regular HTTP application guards, with the key difference being the use of WsException instead of HttpException. Method-scoped and gateway-scoped guards can be implemented using the @UseGuards() decorator. The document also highlights the support for the NestJS project and encourages users to subscribe for updates.

Uploaded by

dharmendra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Search dark_mode

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

Join our Newsletter


Subscribe to stay up to date with the latest Nest updates, features, and videos!

Email address..

Copyright © 2017-2025 MIT by Kamil Mysliwiec design by Jakub Staron


Official NestJS Consulting Trilon.io hosted by Netlify

You might also like