Guards

Guards

μ›Ή μ†ŒμΌ“ guards와 regular guardsμ—λŠ” 차이가 μ—†μŠ΅λ‹ˆλ‹€. μ•Œμ•„μ•Ό ν•  μœ μΌν•œ 것은 HttpException을 λ°œμƒμ‹œν‚€λŠ” λŒ€μ‹  WsException을 μ‚¬μš©ν•΄μ•Ό ν•œλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€.

info 힌트 WsException ν΄λž˜μŠ€λŠ”@nestjs/websockets νŒ¨ν‚€μ§€μ—μ„œ λ…ΈμΆœλ©λ‹ˆλ‹€.

Binding guards

λ‹€μŒμ€ method-scoped guardλ₯Ό μ‚¬μš©ν•˜λŠ” μ˜ˆμ œμž…λ‹ˆλ‹€ (class-scoped도 μž‘λ™ν•©λ‹ˆλ‹€).

@@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 };
}

Last updated