Bird
0
0

What is wrong with this guard usage?

medium📝 Debug Q7 of 15
NestJS - Authentication
What is wrong with this guard usage?
@UseGuards() export class AppController { @Get('data') getData() { return 'data'; } }
AMissing @Controller decorator on class
B@UseGuards() cannot be used on classes
C@UseGuards() requires at least one guard class as argument
DgetData method must be async
Step-by-Step Solution
Solution:
  1. Step 1: Check @UseGuards() usage

    @UseGuards() must receive one or more guard classes; empty parentheses are invalid.
  2. Step 2: Verify other options

    @UseGuards() can be used on classes, @Controller may be missing but not asked, method async not required.
  3. Final Answer:

    @UseGuards() requires at least one guard class as argument -> Option C
  4. Quick Check:

    @UseGuards() needs guard classes [OK]
Quick Trick: Always pass guard classes to @UseGuards() [OK]
Common Mistakes:
  • Leaving @UseGuards() empty
  • Thinking @UseGuards() only works on methods
  • Confusing missing decorators with guard errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes