Track 07 · Lesson 7 of 18Identity and login

Track 07 · Identity and login

Choosing a design

Lesson 7 of 18· 6 min

There’s no single correct auth design. The right one depends on how your app is built, where your API lives, what you can change, and how much a stolen session would hurt. Answer six questions and see the five common setups ranked.

Decision helper

Example answers are selected. Change them

  1. 1. How are your pages built?

  2. 2. Where does your API live?

  3. 3. Do you need SSO, social login or MFA without building it?

  4. 4. Who else calls your API?

  5. 5. How bad would a stolen session be?

  6. 6. Can you change the backend's auth code?

Best fit for these answers

BFF + sealed refresh cookie

A small server next to the frontend catches tokens at login, seals the refresh token in an HttpOnly cookie, and hands the browser only a short-lived access token kept in memory. Everyday API calls still go straight to the API. Strong protection with almost no backend changes.

  • You can run server code next to the frontend, so a BFF is cheap to add.
  • A separate API makes cross-site cookies awkward, which favors tokens or a same-origin BFF.
  • With one client, cookie-based designs stay simple.
  • Long-lived credentials should be out of JavaScript's reach.
  • A BFF wraps an existing token API without changing it.
  • BFF + sealed refresh cookie

    +9
  • Full BFF (token handler)

    +5
  • Hosted identity provider

    +2
  • SPA + token in storage

    -1
  • Server sessions

    -3

Your setup marks the secret map, the lifecycle player and the comparison table in other lessons. A starting point for a team discussion, not a verdict.

The five setups#

  • SPA + token in storage: the simplest to build and the riskiest. Fine for prototypes.
  • Server sessions: the classic in Rails, Django, Laravel and friends. Simple, revocable, needs CSRF protection.
  • BFF + sealed refresh cookie: a small server next to the frontend catches tokens at login, locks the refresh token in an HttpOnly cookie, and hands the browser only a short-lived access token.
  • Full BFF (token handler): the browser never sees any token; every API call goes through your proxy.
  • Hosted identity provider: a specialist service owns accounts, MFA and tokens through OpenID Connect.

The worked example#

The BFF with a sealed refresh cookie has the most moving parts, so the rest of this track uses it as the worked example: it touches every concept. Simpler setups skip pieces of it, and the lifecycle player tells you which pieces your setup skips. Press “Use this in this track” to mark your setup across the lessons.

Check yourself

Your app is a static SPA with no server of its own, calling a separate API. Which setups are realistic?