Bird
0
0

How can you combine an interceptor with a guard to log request details only if the guard passes?

hard📝 Conceptual Q9 of 15
NestJS - Interceptors
How can you combine an interceptor with a guard to log request details only if the guard passes?
AApply the interceptor first, then the guard in the controller decorators
BUse the interceptor inside the guard's canActivate method
CApply the guard first, then the interceptor in the controller decorators
DGuards and interceptors cannot be combined
Step-by-Step Solution
Solution:
  1. Step 1: Understand execution order

    Guards run before interceptors to allow or deny access.
  2. Step 2: Apply decorators in correct order

    Applying guard first ensures interceptor runs only if guard passes.
  3. Final Answer:

    Apply guard first, then interceptor -> Option C
  4. Quick Check:

    Guard before interceptor = Apply the guard first, then the interceptor in the controller decorators [OK]
Quick Trick: Guards run before interceptors in request lifecycle [OK]
Common Mistakes:
  • Reversing order of guard and interceptor
  • Trying to call interceptor inside guard
  • Thinking they cannot be combined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes