Track 07 · Lesson 8 of 18Identity and login

Track 07 · Identity and login

The login lifecycle

Lesson 8 of 18· 10 min

A session lives through many situations: login, reloads, everyday calls, expiring tokens, outages, logout. Step through each one and watch which messages move between the three zones, and how the four pieces of state change.

Lifecycle player

Pick a scenario, then step through it

A user signs in with email and password. Watch the refresh token arrive at your server and never reach the browser.

Browser

Your server

Identity & API

Step 1 of 8

The form submits

If a bot check is enabled its widget adds a token. The form posts with a separate auth client aimed at your own site, with no refresh interceptors.

Look for: login form hook · auth client

CAPTCHA / bot check:
A challenge that tells people from scripts (reCAPTCHA, hCaptcha, Turnstile).
Separate auth client:
A second HTTP client used only for login, refresh and logout, with no refresh logic of its own.
Interceptor:
A hook that runs before every request or after every response in an HTTP client.

The key move#

At login, the refresh token arrives at your server, gets sealed into an HttpOnly cookie, and is stripped from the JSON before the reply reaches the browser. The browser only ever holds the short-lived access token, in memory. Every other scenario builds on that.

Reloads cost a refresh#

Memory doesn’t survive a reload, so on every page load the app asks the refresh endpoint for a new access token, using the cookie. A harmless has_session hint in localStorage decides whether to try at all, so anonymous visitors never fire a refresh that would certainly fail.

Failures are not all equal#

“Session expired” and “server hiccup” look similar from the browser and must be handled oppositely: the first sends the user to log in (and back to the same page afterwards), the second keeps them signed in and offers a retry. The next lessons zoom in on that, and on the token clock.

Check yourself

Why does the app keep a has_session hint in localStorage?