NestJS - GuardsWhy is it important to use the Reflector class when implementing role-based guards in NestJS?ATo handle database transactionsBTo retrieve metadata like roles set by decorators on handlers or controllersCTo inject services into guardsDTo log HTTP requests automaticallyCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand Reflector's purposeReflector reads metadata set by decorators on route handlers or controllers.Step 2: Connect metadata to guard logicRole-based guards use Reflector to get roles metadata to decide access.Final Answer:To retrieve metadata like roles set by decorators on handlers or controllers -> Option BQuick 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 injectionNot using Reflector and hardcoding rolesAssuming Reflector handles database or HTTP
Master "Guards" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Authentication - Local strategy (username/password) - Quiz 8hard Database with Prisma - CRUD with Prisma - Quiz 12easy Database with Prisma - Why Prisma offers type-safe database access - Quiz 1easy Interceptors - Interceptor interface - Quiz 9hard Middleware - Why middleware processes requests before handlers - Quiz 14medium Middleware - Global middleware - Quiz 15hard Pipes - Custom pipes - Quiz 14medium Pipes - Why pipes transform and validate input - Quiz 10hard Pipes - Pipe binding (parameter, method, controller, global) - Quiz 4medium Pipes - File validation pipe - Quiz 5medium