Loading...
Loading...
JsonWebTokenError: jwt expiredThis error means the JWT's 'exp' (expiration) claim is in the past. The token was valid when it was issued but has since expired. This is a security feature — tokens should expire to limit the damage if they are stolen.
Use our JWT Decoder to inspect the exp claim and see exactly when it expired.
Issue a short-lived access token and a long-lived refresh token. Refresh automatically.
async function fetchWithAuth(url) {
let res = await fetch(url, {
headers: { Authorization: `Bearer ${getAccessToken()}` }
});
if (res.status === 401) {
// Token expired — refresh it
await refreshAccessToken();
res = await fetch(url, {
headers: { Authorization: `Bearer ${getAccessToken()}` }
});
}
return res;
}If using jsonwebtoken on Node.js, add a clockTolerance option.
jwt.verify(token, secret, { clockTolerance: 30 }); // 30 seconds