Skip to content

Preserve sessions during network reconnects - #414

Open
0xSolarPunk wants to merge 3 commits into
cfal:mainfrom
pm-alpha:fix/auth-network-reconnect
Open

Preserve sessions during network reconnects#414
0xSolarPunk wants to merge 3 commits into
cfal:mainfrom
pm-alpha:fix/auth-network-reconnect

Conversation

@0xSolarPunk

@0xSolarPunk 0xSolarPunk commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Problem

After laptop wake, the service worker can serve Garcon's cached shell before /api is reachable. Auth bootstrap then treats the transport failure as unauthenticated, redirects an existing session to /login, and may clear a valid token if user validation fails transiently.

Closes #413.

Fix

  • Retry auth status and user validation with bounded backoff and a 5-second per-request timeout.
  • Preserve stored tokens on transport and retryable server failures; clear only on authoritative 401/403 responses.
  • Model exhausted retries as an unavailable/reconnecting state instead of logged out.
  • Suppress login redirects while auth is unavailable.
  • Retry automatically on browser online, visibility restoration, and a 15-second visible-tab recovery interval.
  • Coalesce concurrent recovery checks and expose a manual retry screen.
  • Prevent stale bootstrap checks from overwriting successful login, registration, or logout mutations.
  • Restrict online recovery checks to unavailable sessions so healthy app state is not remounted.
  • Replace raw Failed to fetch login errors with the localized network message.

Testing

  • bun run test — passed
  • bun run check — passed
  • bun run build — passed
  • bun run --cwd integration-tests typecheck — passed
  • Targeted Lightpanda auth reconnect E2E — passed
  • Isolated bun run start --port 0 startup smoke — passed
  • git diff --check — passed

Regression coverage includes status and user-validation transport failures, exhausted retries, retry recovery, token retention, 401/403 invalidation, concurrent-check coalescing, stale login/registration races, protected-route retention, manual browser recovery, healthy online events, registration recovery, and useful login transport errors.

@yongkangc
yongkangc enabled auto-merge (squash) July 28, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid login redirect when auth check fails during network reconnect

2 participants