How do you invalidate a JWT?
235
09-Jun-2025
Updated on 09-Jun-2025
Anubhav Kumar
09-Jun-2025Invalidating a JWT (JSON Web Token) is tricky because JWTs are stateless—once issued, they live independently until they expire. You can’t just delete them from a server-side session store like traditional cookies.
But here are several strategies to invalidate or effectively block JWTs:
1. Use Short Expiration Time (
exp)Set a short lifespan (e.g., 5–15 minutes) for access tokens:
This limits how long a stolen or invalid token can be used.
2. Implement Refresh Tokens (Best Practice)
3. Maintain a Token Blacklist / Blocklist
jticlaim or unique ID).4. Use a Token Version / Timestamp in Claims
Include a
token_versionorlast_password_changein the JWT:5. Force Logout or Invalidation via Server Flag
Store a
isLoggedOutflag or alastLogoutTimeon the server.On every request:
iat(issued at) claim in the JWT.iat < lastLogoutTime, consider it invalid.6. Client-Side Logout
When the user logs out:
localStorage,sessionStorage, or cookies.You Can’t Directly Invalidate a JWT That’s Already Issued
JWTs are self-contained. You can’t reach into the token and revoke it unless:
exp+ refresh token rotation or blacklist check.Summary