Bird
0
0

What happens when you use @UseGuards(AuthGuard, RolesGuard) on a NestJS route handler?Choose the best description.

easy📝 Conceptual Q11 of 15
NestJS - Guards

What happens when you use @UseGuards(AuthGuard, RolesGuard) on a NestJS route handler?

Choose the best description.

AOnly AuthGuard is checked; RolesGuard is ignored.
BBoth AuthGuard and RolesGuard must allow access for the request to proceed.
CEither AuthGuard or RolesGuard allowing access is enough to proceed.
DGuards run in parallel but only the first to approve grants access.
Step-by-Step Solution
Solution:
  1. Step 1: Understand how multiple guards work in NestJS

    When multiple guards are used with @UseGuards(), NestJS runs them in sequence and requires all to approve access.
  2. Step 2: Apply this to the given guards

    Both AuthGuard and RolesGuard must return true for the request to proceed.
  3. Final Answer:

    Both AuthGuard and RolesGuard must allow access for the request to proceed. -> Option B
  4. Quick Check:

    All guards must approve = A [OK]
Quick Trick: All guards must pass for access, not just one [OK]
Common Mistakes:
  • Thinking only one guard needs to pass
  • Assuming guards run in parallel and race
  • Believing guards are ignored if one fails

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes