Bird
0
0

Examine this NestJS controller snippet:

medium📝 Debug Q7 of 15
NestJS - Guards

Examine this NestJS controller snippet:

@UseGuards(AuthGuard || RolesGuard)
@Get('settings')
settings() {
  return 'Settings';
}

What is wrong with this guard application?

ALogical operators like <code>||</code> cannot be used inside <code>@UseGuards</code>.
BGuards must be passed as a single array, not separated by operators.
CThe <code>@UseGuards</code> decorator requires only one guard at a time.
DGuards should be applied using <code>@ApplyGuards</code> instead.
Step-by-Step Solution
Solution:
  1. Step 1: Review @UseGuards syntax

    The decorator expects guard classes or instances separated by commas, not logical expressions.
  2. Step 2: Identify the error

    Using || is invalid syntax and will cause a compilation or runtime error.
  3. Final Answer:

    Logical operators like || cannot be used inside @UseGuards. -> Option A
  4. Quick Check:

    Use commas, not logical operators, to combine guards [OK]
Quick Trick: Use commas, not logical operators, to combine guards [OK]
Common Mistakes:
  • Using && or || inside @UseGuards
  • Passing guards as a single array without commas
  • Confusing @UseGuards with other decorators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes