Bird
0
0

Which of the following is the correct way to create a JWT authentication guard class in NestJS?

easy📝 Syntax Q3 of 15
NestJS - Guards
Which of the following is the correct way to create a JWT authentication guard class in NestJS?
Aexport class JwtAuthGuard implements AuthGuard('jwt') {}
Bexport class JwtAuthGuard extends AuthGuard('jwt') {}
Cexport function JwtAuthGuard() { return AuthGuard('jwt'); }
Dexport const JwtAuthGuard = new AuthGuard('jwt');
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to extend AuthGuard

    In NestJS, guards extend the AuthGuard class with the strategy name.
  2. Step 2: Identify correct syntax for class extension

    Correct syntax is: export class JwtAuthGuard extends AuthGuard('jwt') {}.
  3. Final Answer:

    export class JwtAuthGuard extends AuthGuard('jwt') {} -> Option B
  4. Quick Check:

    Extend AuthGuard('jwt') with class [OK]
Quick Trick: Extend AuthGuard('jwt') to create JWT guard class [OK]
Common Mistakes:
  • Using implements instead of extends
  • Trying to create guard as a function
  • Assigning AuthGuard instance to const

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes