Skip to content

Commit 7ba2717

Browse files
docs(specs): sessions stick for 90 days and the SPA renews them
The SPA never called /api/auth/refresh, so every session ended with the 15-minute access cookie. Spell out the client's job (refresh on load behind a non-secret hint cookie, and once on any 401), lengthen the sliding refresh window to 90 days, and say refresh writes nothing to the public store. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TGqwPjt3v4eMfiHpPmCKnR
1 parent 2c79750 commit 7ba2717

3 files changed

Lines changed: 76 additions & 5 deletions

File tree

‎plans/sticky-sessions.md‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
status: in-progress
3+
depends: []
4+
specs:
5+
- specs/behaviors/authorization.md
6+
- specs/api/conventions.md
7+
issues: []
8+
---
9+
10+
# Plan: Sessions that stick for months
11+
12+
## Scope
13+
14+
Chris (2026-10-15): "I get logged out soooo quick. I want the login to be
15+
super sticky like weeks/months." The spec already promised a 30-day
16+
sliding session, but the SPA never called `POST /api/auth/refresh`, so
17+
every session ended when the 15-minute access cookie expired. And the
18+
refresh endpoint revoked the old refresh token with a public commit,
19+
which the spec rules out ("no per-request writes anywhere").
20+
21+
**In:** refresh TTL 90 days, sliding; a non-secret `cfp_has_session` hint
22+
cookie set and cleared with the refresh cookie; the SPA refreshes on load
23+
when the hint is present and `/me` says anonymous, and on any 401 (once,
24+
single-flight, then retries); refresh no longer writes a revocation.
25+
26+
**Out:** refresh-token reuse detection (still deferred per the spec);
27+
longer access tokens.
28+
29+
## Implements
30+
31+
- [behaviors/authorization.md](../specs/behaviors/authorization.md#session-model--stateless-jwts)
32+
- [api/conventions.md](../specs/api/conventions.md) — cookie list.
33+
34+
## Approach
35+
36+
1. `REFRESH_TTL_SECONDS` (90 days) exported from `auth/jwt.ts`, used by the
37+
JWT, the cookie and the session metadata.
38+
2. `setSessionCookies` / `clearSessionCookies` handle `cfp_has_session`.
39+
3. `refreshSession()` + `hasSessionHint()` in `lib/api.ts`; `request()`
40+
retries after a refresh on 401 (not for `/api/auth/*`); `useAuth`
41+
refreshes on load when hinted.
42+
43+
## Validation
44+
45+
- [ ] `npm run type-check && npm run lint && npm test` clean.
46+
- [ ] API test: refresh sets a 90-day refresh cookie and the hint, writes no
47+
revocation; logout clears the hint.
48+
- [ ] Web tests: load-time refresh only with the hint; a 401 refreshes once
49+
and retries.
50+
- [ ] Devbox: with the access cookie gone and the refresh cookie kept, a
51+
reload comes back signed in.
52+
53+
## Risks / unknowns
54+
55+
- Members signed in before this ships have no hint cookie: their next
56+
signed-in action still recovers through the 401 path, and the first
57+
successful refresh sets the hint.
58+
59+
## Notes
60+
61+
## Follow-ups

‎specs/api/conventions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ For paginated lists, the `data` is an array and `metadata` includes pagination:
7171

7272
## Authentication
7373

74-
- Two cookies carry **stateless JWTs**: `cfp_session` (15-minute access JWT) and `cfp_refresh` (30-day refresh JWT, path-scoped to `/api/auth/refresh`). Cleared by `POST /api/auth/logout`. See [behaviors/authorization.md](../behaviors/authorization.md) for the full token model and [api/auth.md](auth.md) for the surviving session endpoints.
74+
- Two cookies carry **stateless JWTs**: `cfp_session` (15-minute access JWT) and `cfp_refresh` (90-day refresh JWT, path-scoped to `/api/auth/refresh`), plus the non-secret `cfp_has_session` hint. Cleared by `POST /api/auth/logout`. See [behaviors/authorization.md](../behaviors/authorization.md) for the full token model and [api/auth.md](auth.md) for the surviving session endpoints.
7575
- Both cookies: `HttpOnly`, `Secure`, `SameSite=Lax`. In development, `Secure` is dropped when the host is `localhost`.
7676
- There is no `sessions` table or sheet. Revocation is tracked in a small `revocations` sheet plus an in-memory `Set` of revoked `jti`s.
7777
- The endpoints that *issue* JWTs (GitHub OAuth callback, account-claim flow) are not yet specified. The endpoints that *manage* JWTs once issued are in [api/auth.md](auth.md).

‎specs/behaviors/authorization.md‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ Sessions are **stateless JWTs**, not database rows. There is no `sessions` sheet
6464
### Tokens
6565

6666
- **Access JWT** — 15-minute lifetime. Sent on every API request in the `cfp_session` cookie. Payload: `{ sub: personId, jti: uuidv7, accountLevel, exp, iat }`.
67-
- **Refresh JWT** — 30-day lifetime. Sent only on refresh requests in a separate `cfp_refresh` cookie (path-scoped to `/api/auth/refresh`). Payload: `{ sub: personId, jti, exp, iat }`.
67+
- **Refresh JWT** — 90-day lifetime. Sent only on refresh requests in a separate `cfp_refresh` cookie (path-scoped to `/api/auth/refresh`). Payload: `{ sub: personId, jti, exp, iat }`. Every refresh issues a new one, so the 90 days run from the last visit, not from sign-in.
68+
- **Session hint** — a `cfp_has_session=1` cookie set and cleared alongside the refresh cookie, with the same lifetime, path `/`, and **not** `HttpOnly`. It carries no secret; it only tells the SPA a refresh is worth attempting, so anonymous visitors never trigger one.
6869

69-
Both cookies: `HttpOnly`, `Secure`, `SameSite=Lax`. `Secure` is dropped only when host is `localhost` in development.
70+
The token cookies: `HttpOnly`, `Secure`, `SameSite=Lax`. `Secure` is dropped only when host is `localhost` in development.
7071

7172
Signing: HS256 with `CFP_JWT_SIGNING_KEY` (server-managed secret, rotated on a cadence). Rotation triggers re-issue of all tokens on next refresh.
7273

@@ -77,7 +78,7 @@ GitHub OAuth callback resolves to a Person
7778
(directly, or via /account-claim — see behaviors/account-migration.md)
7879
│
7980
▼
80-
Issue access JWT (15m) + refresh JWT (30d) ─▶ Set cookies
81+
Issue access JWT (15m) + refresh JWT (90d) ─▶ Set cookies
8182
│
8283
▼
8384
Subsequent requests carry access JWT
@@ -90,7 +91,16 @@ GitHub OAuth callback resolves to a Person
9091

9192
There's a third short-lived JWT — the **claim-pending JWT** issued by the OAuth callback when legacy candidates exist. It has `scope: "claim"`, lifetime 5 minutes, and is accepted only by the `/api/account-claim/*` endpoints. See [api/account-claim.md](../api/account-claim.md).
9293

93-
The access-token TTL is intentionally short so revocation has a small blast radius. The refresh-token TTL is "session length" — 30 days of inactivity logs you out.
94+
The access-token TTL is intentionally short so revocation has a small blast radius. The refresh-token TTL is "session length" — 90 days of inactivity logs you out; anyone who visits at least once a season stays signed in indefinitely.
95+
96+
**The SPA keeps the session alive.** The access cookie expires 15 minutes after it was issued and the browser drops it, so a returning member's first request arrives without one. The SPA therefore:
97+
98+
1. On load, when `/api/auth/me` reports no person but `cfp_has_session` is present, calls `POST /api/auth/refresh` once and re-reads `/api/auth/me`.
99+
2. On any `401` from another API call (hint or not — a 401 means the caller tried something that needs a session), calls `POST /api/auth/refresh` once (concurrent 401s share one refresh) and retries the request; if the refresh fails, the `401` stands and the member is treated as signed out.
100+
101+
Signing in is the slowest thing a member does on this site, and a lapsed session silently turns their next action into a sign-in detour. Stay signed in unless they sign out or don't come back for a season.
102+
103+
**Refresh writes nothing to the public store.** It issues the new pair and swaps the private session-metadata entry; the old refresh token is not revoked — it stays valid until it expires, the same exposure as the token that replaces it (see [Why not refresh-rotation tracking](#why-not-refresh-rotation-tracking)). A revocation per refresh would be a public commit per active member every quarter hour.
94104

95105
### Revocation
96106

0 commit comments

Comments
 (0)