Bird
0
0

You want to apply a guard that blocks access to all routes except one specific route in a controller. Which approach correctly uses guard binding levels to achieve this?

hard📝 Application Q15 of 15
NestJS - Guards
You want to apply a guard that blocks access to all routes except one specific route in a controller. Which approach correctly uses guard binding levels to achieve this?
ABind the guard globally and use a route-level guard to allow the exception route.
BBind the guard only on the exception route to block all others.
CBind the guard on the controller and override it with a route-level guard that allows the exception.
DBind the guard globally and remove it from the exception route using @SkipGuards.
Step-by-Step Solution
Solution:
  1. Step 1: Understand guard override behavior

    Controller-level guards apply to all routes in that controller but can be overridden by route-level guards.
  2. Step 2: Apply guard to block all except one route

    Binding the guard on the controller blocks all routes; then a route-level guard on the exception route can allow access.
  3. Final Answer:

    Bind the guard on the controller and override it with a route-level guard that allows the exception. -> Option C
  4. Quick Check:

    Controller guard + route override = selective access [OK]
Quick Trick: Use controller guard plus route guard override for exceptions [OK]
Common Mistakes:
  • Trying to remove global guards per route (not supported)
  • Binding guard only on exception route (wrong logic)
  • Assuming global guard can be skipped per route

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes