Bird
0
0

What will happen if you apply multiple guards using @UseGuards(AuthGuard, RolesGuard) on a route and AuthGuard returns false?

medium📝 component behavior Q5 of 15
NestJS - Authentication
What will happen if you apply multiple guards using @UseGuards(AuthGuard, RolesGuard) on a route and AuthGuard returns false?
AAccess is denied immediately without checking RolesGuard
BBoth guards run and access is granted if RolesGuard returns true
COnly RolesGuard runs and decides access
DAn error occurs due to multiple guards
Step-by-Step Solution
Solution:
  1. Step 1: Understand guard execution order

    Guards run in order; if any guard returns false, access is denied immediately.
  2. Step 2: Apply this to given guards

    AuthGuard returns false, so RolesGuard is not checked and access is denied.
  3. Final Answer:

    Access is denied immediately without checking RolesGuard -> Option A
  4. Quick Check:

    Multiple guards stop at first false [OK]
Quick Trick: First guard returning false blocks all others [OK]
Common Mistakes:
  • Assuming all guards run regardless
  • Believing later guards can override false
  • Thinking multiple guards cause errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes