-
Works for a short time (15 minutes).
-
If it expires, you cannot open doors anymore.
-
You don’t go back to reception every time, you just use your card.
-
You keep it during your entire stay (7 days).
-
If your room card expires, you go to reception with your ID.
-
They give you a new room card (new access token).
-
You never show your ID to open rooms — only when renewing your card.
-
Lives 15 minutes.
-
Used on every API request to say "this is me".
-
It’s fast, lightweight, and does NOT require hitting the database.
Example:
-
Navigate pages
-
Calling API endpoints
-
Viewing profile
-
Fetching products
Once it expires → 401 Unauthorized
-
Lives much longer (7 days).
-
Stored securely in the browser (usually httpOnly cookie).
-
Its only job:
That’s it.
Not used for navigation.
Not used for normal API calls.
Only used for renewing the access token.
- User would need to log in every 15 minutes.
Unusable.
- If a hacker steals it → they can stay logged in for 7 days.
Very dangerous.
-
Access token short = security
-
Refresh token long = convenience
-
Refresh token stored in DB = detect theft
-
Access token stored on client = fast navigation
Your app logs him in and receives:
-
Access token (expires 15 minutes)
-
Refresh token (expires 7 days)
Works normally because access token still valid.
Access token expires → user gets 401.
Browser automatically sends refresh token to backend:
“Hey, my card expired. Here’s my ID. Give me a new one.”
Backend:
-
Checks refresh token from DB (active? expired? revoked? IP safe?)
-
Issues new access token
-
Rotates refresh token (optional)
-
Returns new access token
User stays logged in, doesn’t even notice.
-
Access token expired
-
Refresh token still valid for 7 days
Browser → server:
"I still have a refresh token, give me a new access token."
User is still logged in.
This is exactly the Remember Me experience.
Refresh token expires → user must log in again.
-
short life
-
for access
-
expires fast
-
used constantly
-
long life
-
for login persistence
-
used rarely
-
only used to get new access tokens
-
stored & monitored for security
Here comes the fun part — turning your refresh-token logic into a visual map. Think of it like drawing the nervous system of your authentication brain.
a clear, step-by-step conceptual diagram of access + refresh rotation flow, exactly matching how implementation works.
No fancy jargon — just the real logic => - Token Flow Diagram