JWT Token Expired: How to Debug and Fix It

Published April 2025 · 6 min read

Getting a "Token Expired" or "jwt expired" error? This means the exp (expiration) claim in your JWT has passed. Here's how to debug and fix it.

Step 1: Decode Your Token

Use our JWT Decoder to paste your token and see the payload. Look for the exp field — it's a Unix timestamp.

{
  "sub": "1234567890",
  "name": "John Doe",
  "exp": 1713000000
}

Convert that timestamp using our Unix Timestamp Converter to see when it expired.

Step 2: Common Causes

Clock Skew

Your server's clock might be off. Even a few seconds difference can cause expired token errors. Fix: sync your server time with NTP.

Token Lifetime Too Short

If your access token expires in 5 minutes but your API call takes longer, you'll get this error. Consider increasing the lifetime or implementing refresh tokens.

Not Refreshing Tokens

Access tokens should be short-lived. Use refresh tokens to get new access tokens before they expire.

// Token refresh flow
if (isTokenExpired(accessToken)) {
  const newToken = await refreshAccessToken(refreshToken);
  // retry the request with newToken
}

Step 3: Fix Strategies

  • Implement a token refresh mechanism
  • Add a buffer (refresh 30 seconds before expiry)
  • Use interceptors in Axios/Fetch to auto-refresh
  • Store token expiry time client-side and check before requests

Quick Check Function (JavaScript)

function isTokenExpired(token) {
  const payload = JSON.parse(atob(token.split('.')[1]));
  return payload.exp * 1000 < Date.now();
}

Related Tools