Bird
0
0

Which NestJS decorator is used to apply a JWT authentication guard to a controller method?

easy📝 Conceptual Q2 of 15
NestJS - Guards
Which NestJS decorator is used to apply a JWT authentication guard to a controller method?
A@JwtAuth()
B@UseGuards()
C@AuthGuard()
D@JwtGuard()
Step-by-Step Solution
Solution:
  1. Step 1: Recall how guards are applied in NestJS

    Guards are applied using the @UseGuards() decorator.
  2. Step 2: Confirm the correct decorator for JWT guard

    The JWT guard class is passed inside @UseGuards(), e.g., @UseGuards(JwtAuthGuard).
  3. Final Answer:

    @UseGuards() -> Option B
  4. Quick Check:

    Apply guard = @UseGuards() [OK]
Quick Trick: Use @UseGuards() to apply any guard in NestJS [OK]
Common Mistakes:
  • Using non-existent decorators like @JwtAuth()
  • Confusing @AuthGuard() as a decorator
  • Assuming @JwtGuard() exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes