Bird
0
0

Why is it important to use the Reflector class when implementing role-based guards in NestJS?

hard📝 Conceptual Q10 of 15
NestJS - Guards
Why is it important to use the Reflector class when implementing role-based guards in NestJS?
ATo handle database transactions
BTo retrieve metadata like roles set by decorators on handlers or controllers
CTo inject services into guards
DTo log HTTP requests automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand Reflector's purpose

    Reflector reads metadata set by decorators on route handlers or controllers.
  2. Step 2: Connect metadata to guard logic

    Role-based guards use Reflector to get roles metadata to decide access.
  3. Final Answer:

    To retrieve metadata like roles set by decorators on handlers or controllers -> Option B
  4. Quick Check:

    Reflector reads decorator metadata for guards [OK]
Quick Trick: Reflector reads roles metadata for guards to check [OK]
Common Mistakes:
  • Confusing Reflector with logging or injection
  • Not using Reflector and hardcoding roles
  • Assuming Reflector handles database or HTTP

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes