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

Was this helpful?