Bird
0
0

Identify the error in this NestJS controller snippet using multiple guards:

medium📝 Debug Q14 of 15
NestJS - Guards

Identify the error in this NestJS controller snippet using multiple guards:

@UseGuards(AuthGuard RolesGuard)
@Get('data')
getData() {
  return 'Data';
}
AThe @Get decorator is misplaced
BGuards must be passed as an array
CMissing comma between guards in @UseGuards()
DGuards cannot be combined on the same method
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of @UseGuards()

    The guards inside @UseGuards() must be separated by commas.
  2. Step 2: Identify the error in the snippet

    The snippet misses a comma between AuthGuard and RolesGuard, causing a syntax error.
  3. Final Answer:

    Missing comma between guards in @UseGuards() -> Option C
  4. Quick Check:

    Comma missing between guards = D [OK]
Quick Trick: Check commas between guards inside @UseGuards() [OK]
Common Mistakes:
  • Forgetting commas between guards
  • Passing guards as an array incorrectly
  • Misplacing decorators order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes