Bird
0
0

Why might a JWT strategy fail to authenticate a request in NestJS Passport integration?

medium📝 Debug Q7 of 15
NestJS - Authentication
Why might a JWT strategy fail to authenticate a request in NestJS Passport integration?
AThe strategy class is not decorated with @Injectable()
BThe controller method lacks @Get() decorator
CThe JWT token is missing or invalid in the request headers
DThe AuthGuard is not imported from @nestjs/common
Step-by-Step Solution
Solution:
  1. Step 1: Understand JWT strategy authentication

    JWT strategy checks for a valid token in request headers.
  2. Step 2: Identify common failure cause

    If token is missing or invalid, authentication fails.
  3. Final Answer:

    The JWT token is missing or invalid in the request headers -> Option C
  4. Quick Check:

    JWT auth fails if token missing/invalid [OK]
Quick Trick: JWT strategy needs valid token in headers to authenticate [OK]
Common Mistakes:
  • Confusing decorator issues with token problems
  • Assuming controller decorators affect authentication
  • Importing AuthGuard from wrong package

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes