Bird
0
0

Identify the error in this JWT guard implementation: ```typescript import { Injectable } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; @Injectable() export class JwtAuthGuard implements AuthGuard('jwt') {} ```

medium📝 Debug Q6 of 15
NestJS - Guards
Identify the error in this JWT guard implementation: ```typescript import { Injectable } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; @Injectable() export class JwtAuthGuard implements AuthGuard('jwt') {} ```
AAuthGuard import path is incorrect
BMissing @UseGuards decorator
CMissing constructor in JwtAuthGuard
DJwtAuthGuard should extend AuthGuard, not implement it
Step-by-Step Solution
Solution:
  1. Step 1: Review class declaration syntax

    JwtAuthGuard must extend AuthGuard, not implement it.
  2. Step 2: Identify correct inheritance

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

    JwtAuthGuard should extend AuthGuard, not implement it -> Option D
  4. Quick Check:

    Extend AuthGuard, don't implement [OK]
Quick Trick: Use extends, not implements, for AuthGuard subclass [OK]
Common Mistakes:
  • Using implements instead of extends
  • Forgetting @UseGuards is unrelated to class syntax
  • Incorrect import path is not the issue here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes