Guards

Guards

๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค ๊ฐ€๋“œ์™€ ์ผ๋ฐ˜ ๊ฐ€๋“œ ์‚ฌ์ด์—๋Š” ์ฐจ์ด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์•Œ์•„์•ผํ•  ์œ ์ผํ•œ ๊ฒƒ์€ HttpException์„ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๋Œ€์‹  RpcException์„ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

info ํžŒํŠธ RpcException ํด๋ž˜์Šค๋Š”@nestjs/microservices ํŒจํ‚ค์ง€์—์„œ ๋…ธ์ถœ๋ฉ๋‹ˆ๋‹ค.

Binding guards

๋‹ค์Œ์€ method-scoped guard๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค (class-scoped๋„ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค).

@@filename()
@UseGuards(AuthGuard)
@MessagePattern({ cmd: 'sum' })
accumulate(data: number[]): number {
  return (data || []).reduce((a, b) => a + b);
}

Last updated

Was this helpful?