Bird
0
0

Identify the error in this JWT verification code snippet:

medium📝 Debug Q6 of 15
Rest API - Authentication and Authorization
Identify the error in this JWT verification code snippet:
const jwt = require('jsonwebtoken');
const token = req.headers.authorization;
const decoded = jwt.verify(token, 'secretKey');
console.log(decoded);
AUsing 'jsonwebtoken' instead of 'jwt-simple'
BIncorrect secret key format
CMissing check if token exists before verification
DLogging decoded token is not allowed
Step-by-Step Solution
Solution:
  1. Step 1: Review token retrieval

    The code gets token from headers but does not check if it exists before verifying.
  2. Step 2: Identify missing validation

    If token is missing, calling verify will throw an error; a check is needed first.
  3. Final Answer:

    Missing check if token exists before verification -> Option C
  4. Quick Check:

    Always check token presence before verify [OK]
Quick Trick: Check token exists before verify call [OK]
Common Mistakes:
  • Skipping token existence check
  • Confusing jwt libraries
  • Thinking logging decoded token is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes