Bird
0
0

What will be the final result when accessing a route in that controller?

hard📝 Conceptual Q9 of 15
NestJS - Guards
Consider this scenario: You have a global guard and a controller guard. The global guard denies access, but the controller guard allows it. What will be the final result when accessing a route in that controller?
AAccess will be allowed because the controller guard overrides the global guard
BBoth guards will run but the last one decides access
CAn error will occur due to conflicting guard results
DAccess will be denied because the global guard runs first and blocks the request
Step-by-Step Solution
Solution:
  1. Step 1: Understand guard execution order

    Global guards run before controller guards in NestJS.
  2. Step 2: Analyze guard effect on request

    If the global guard denies access, the request is stopped immediately, so controller guard is not reached.
  3. Final Answer:

    Access will be denied because the global guard runs first and blocks the request -> Option D
  4. Quick Check:

    Global guard deny stops request early = Access will be denied because the global guard runs first and blocks the request [OK]
Quick Trick: Global guard deny stops request before controller guards run [OK]
Common Mistakes:
  • Assuming controller guard can override global guard
  • Expecting errors from guard conflicts
  • Thinking last guard decides access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes