Bird
0
0

In NestJS, what is the primary function of a guard that checks user roles?

easy📝 Conceptual Q1 of 15
NestJS - Guards
In NestJS, what is the primary function of a guard that checks user roles?
ATo validate the format of incoming request data
BTo restrict access to routes based on user roles
CTo log user activity for auditing purposes
DTo handle exceptions thrown in controllers
Step-by-Step Solution
Solution:
  1. Step 1: Understand Guards

    Guards in NestJS are used to determine whether a request should be handled by the route handler or not.
  2. Step 2: Role-based Guard Purpose

    A role-based guard specifically checks the user's roles to allow or deny access to certain routes.
  3. Final Answer:

    To restrict access to routes based on user roles -> Option B
  4. Quick Check:

    Guards control access based on roles [OK]
Quick Trick: Guards restrict access by roles, not data validation [OK]
Common Mistakes:
  • Confusing guards with pipes that validate data
  • Thinking guards handle logging or exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes