Bird
0
0

Identify the error in this code snippet applying multiple guards:

medium📝 Debug Q6 of 15
NestJS - Guards

Identify the error in this code snippet applying multiple guards:

@UseGuards([AuthGuard, RolesGuard])
@Get('dashboard')
dashboard() {
  return 'Dashboard';
}
AThe @Get decorator is missing parentheses
BThe method should be async to use guards
CGuards should be passed as separate arguments, not inside an array
DGuards must be applied inside the controller, not on methods
Step-by-Step Solution
Solution:
  1. Step 1: Check @UseGuards syntax

    @UseGuards expects guards as separate arguments, not an array.
  2. Step 2: Identify the error

    Passing guards inside an array causes a runtime error or guards not applied correctly.
  3. Final Answer:

    Guards should be passed as separate arguments, not inside an array -> Option C
  4. Quick Check:

    Pass guards as arguments, not array [OK]
Quick Trick: Do not wrap guards in array for @UseGuards [OK]
Common Mistakes:
  • Passing guards as array
  • Misusing decorators syntax
  • Assuming async needed for guards

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes