Bird
0
0

Identify the error in this NestJS token validation code:

medium📝 Debug Q6 of 15
NestJS - Authentication
Identify the error in this NestJS token validation code:
const payload = jwtService.verify(token, { secret: 'wrongSecret' });
AToken must be decoded, not verified
BMissing async keyword on verify method
CUsing incorrect secret causes verification to fail
DSecret should be passed as a string array
Step-by-Step Solution
Solution:
  1. Step 1: Check secret usage in verify method

    The secret must match the one used to sign the token; otherwise verification fails.
  2. Step 2: Confirm verify method is synchronous

    verify is synchronous; no async keyword needed.
  3. Final Answer:

    Using incorrect secret causes verification to fail -> Option C
  4. Quick Check:

    Wrong secret = verification failure [OK]
Quick Trick: Secret must match signing secret for verify() success [OK]
Common Mistakes:
  • Assuming verify is async
  • Passing secret as array
  • Using decode instead of verify for validation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions