Bird
0
0

Which decorator is commonly used to specify roles required by a role-based guard in NestJS?

easy📝 Conceptual Q2 of 15
NestJS - Guards
Which decorator is commonly used to specify roles required by a role-based guard in NestJS?
A@Roles()
B@Injectable()
C@Controller()
D@Get()
Step-by-Step Solution
Solution:
  1. Step 1: Recall decorators related to roles

    The @Roles() decorator is used to define roles allowed for a route.
  2. Step 2: Differentiate from other decorators

    @Injectable() marks services, @Controller() marks controllers, @Get() marks HTTP GET routes.
  3. Final Answer:

    @Roles() -> Option A
  4. Quick Check:

    Role decorator = @Roles() [OK]
Quick Trick: Use @Roles() to specify allowed roles on routes [OK]
Common Mistakes:
  • Using @Injectable() to specify roles
  • Confusing route decorators with role decorators
  • Omitting role decorators entirely

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes