Bird
0
0

Which of the following is the correct way to apply a Passport.js local strategy in a NestJS controller?

easy📝 Syntax Q12 of 15
NestJS - Authentication
Which of the following is the correct way to apply a Passport.js local strategy in a NestJS controller?
A@UseGuards('local')
B@UseGuards(LocalStrategy)
C@UseGuards(AuthGuard('local'))
D@UseGuards(PassportLocal)
Step-by-Step Solution
Solution:
  1. Step 1: Recall NestJS guard syntax

    Passport strategies are applied using AuthGuard with the strategy name as a string.
  2. Step 2: Match correct syntax

    The correct syntax is @UseGuards(AuthGuard('local')) to apply the local strategy guard.
  3. Final Answer:

    @UseGuards(AuthGuard('local')) -> Option C
  4. Quick Check:

    UseGuards with AuthGuard('strategy') [OK]
Quick Trick: Use AuthGuard with strategy name string [OK]
Common Mistakes:
  • Passing strategy class instead of string
  • Omitting AuthGuard wrapper
  • Using incorrect decorator syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes