NestJS - GuardsWhich 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');Check Answer
Step-by-Step SolutionSolution:Step 1: Understand how to extend AuthGuardIn NestJS, guards extend the AuthGuard class with the strategy name.Step 2: Identify correct syntax for class extensionCorrect syntax is: export class JwtAuthGuard extends AuthGuard('jwt') {}.Final Answer:export class JwtAuthGuard extends AuthGuard('jwt') {} -> Option BQuick Check:Extend AuthGuard('jwt') with class [OK]Quick Trick: Extend AuthGuard('jwt') to create JWT guard class [OK]Common Mistakes:Using implements instead of extendsTrying to create guard as a functionAssigning AuthGuard instance to const
Master "Guards" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Authentication - Session-based authentication - Quiz 2easy Database with Prisma - Schema definition - Quiz 15hard Database with TypeORM - Migrations - Quiz 1easy Guards - Reflector and custom decorators - Quiz 10hard Guards - Guard interface (canActivate) - Quiz 9hard Interceptors - Response transformation - Quiz 5medium Interceptors - Cache interceptor - Quiz 1easy Interceptors - Interceptor interface - Quiz 5medium Middleware - Global middleware - Quiz 11easy Pipes - Pipe binding (parameter, method, controller, global) - Quiz 7medium