Bird
0
0

What will happen if you bind a guard globally and also bind a different guard on a specific controller in NestJS?

medium📝 component behavior Q5 of 15
NestJS - Guards
What will happen if you bind a guard globally and also bind a different guard on a specific controller in NestJS?
AOnly the global guard will run, controller guard is ignored
BOnly the controller guard will run, global guard is ignored
CBoth global and controller guards will run for routes in that controller
DAn error will occur due to conflicting guards
Step-by-Step Solution
Solution:
  1. Step 1: Recall guard execution hierarchy

    Global guards run first, then controller-level guards, then route-level guards.
  2. Step 2: Analyze combined guard behavior

    Both global and controller guards run for routes inside that controller.
  3. Final Answer:

    Both global and controller guards will run for routes in that controller -> Option C
  4. Quick Check:

    Global + controller guards both execute = Both global and controller guards will run for routes in that controller [OK]
Quick Trick: Global guards run before controller guards on requests [OK]
Common Mistakes:
  • Assuming guards override each other
  • Expecting errors from multiple guards
  • Thinking only one guard applies per route

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes