Bird
0
0

Given the following code snippet, what will be the output if the token is expired?

medium📝 Predict Output Q4 of 15
NestJS - Authentication
Given the following code snippet, what will be the output if the token is expired?
try {
  const payload = jwtService.verify(token);
  return 'Valid Token';
} catch (e) {
  return 'Invalid Token';
}
AInvalid Token
BValid Token
CToken Expired Error
DUndefined
Step-by-Step Solution
Solution:
  1. Step 1: Understand jwtService.verify behavior on expired token

    When a token is expired, verify throws an error caught by catch block.
  2. Step 2: Analyze catch block return value

    The catch block returns 'Invalid Token' on any verification error including expiration.
  3. Final Answer:

    Invalid Token -> Option A
  4. Quick Check:

    Expired token triggers catch = 'Invalid Token' [OK]
Quick Trick: Expired tokens cause verify() to throw, caught as invalid [OK]
Common Mistakes:
  • Assuming verify returns error string
  • Expecting 'Token Expired Error' directly
  • Ignoring try-catch behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions