> For the complete documentation index, see [llms.txt](https://jakekwak.gitbook.io/nestjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jakekwak.gitbook.io/nestjs/websockets/guards.md).

# Guards

## Guards

웹 소켓 **guards**와 [regular guards](https://app.gitbook.com/guards)에는 차이가 없습니다. 알아야 할 유일한 것은 `HttpException`을 발생시키는 대신 `WsException`을 사용해야 한다는 것입니다.

> info **힌트** `WsException` 클래스는`@nestjs/websockets` 패키지에서 노출됩니다.

## Binding guards

다음은 method-scoped guard를 사용하는 예제입니다 (class-scoped도 작동합니다).

```typescript
@@filename()
@UseGuards(AuthGuard)
@SubscribeMessage('events')
handleEvent(client: Client, data: unknown): WsResponse<unknown> {
  const event = 'events';
  return { event, data };
}
@@switch
@UseGuards(AuthGuard)
@SubscribeMessage('events')
handleEvent(client, data) {
  const event = 'events';
  return { event, data };
}
```
