Skip to content

fix(web): sign in again when an auth proxy's session ends - #105

Merged
mathieuletyrant merged 2 commits into
mainfrom
claude/snag-pwa-cloudflare-session-t9uc85
Nov 23, 2026
Merged

mathieuletyrant merged 2 commits into
mainfrom
claude/snag-pwa-cloudflare-session-t9uc85

Conversation

@mathieuletyrant

@mathieuletyrant mathieuletyrant commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

What

  • Service worker (sw.js, cache snug-v4): a navigation is now fetched as it is, instead of as a new Request("/"). The answer is still saved as the app shell, and the cached shell is only served when the network fails.
  • api(): calls are sent with redirect: "manual". A redirect reloads the page (at most once a minute) and is reported as an ApiError with status 0. Status 0 makes the screen show "unreachable" rather than Snug's own sign-in form.

Nothing checks for Cloudflare. This works for any auth proxy that redirects to its sign-in page: Cloudflare Access, Authelia, Authentik, oauth2-proxy… Without a proxy, the redirect path never runs.

Why

Found with Cloudflare Access. Once its session ends, Access redirects every request to its sign-in page, which is on another domain. Snug's service worker could not follow that redirect, so its fetch failed. It took that as being offline and served the cached app and the last data seen. The PWA looked fine, but every action failed and the sign-in page never appeared.

In plain words

  • A navigation's own request lets the browser follow a redirect, even one to another site. A request built by the page or the service worker cannot.
  • redirect: "manual" returns a placeholder (type: "opaqueredirect") instead of following. Snug's API never redirects, so that answer always means the proxy in front wants a new sign-in.
  • Not covered: a proxy that answers API calls with a 401 instead of a redirect. Snug would take that 401 as "signed out" and show its own sign-in form.

Checks

bun run typecheck and bun test pass. Checked in Chromium against a fake auth proxy that redirects with a 302 to another origin, with the service worker active. After the session "expired", opening a page and a refetch inside the app both landed on the fake sign-in page.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MqWWDWYeR6E8VJqWwNY7wg

Once Access's session expired, the service worker fetched every navigation
as a fresh cross-origin request: the redirect to the Access sign-in failed,
and the cached app shell and last data came back instead. The PWA looked
fine but every action failed, with no way to sign in again.

Navigations are now fetched as they are, so the browser follows the Access
redirect; the cached shell is only for a network that fails. API calls use
`redirect: "manual"`: a redirect (Snug's API never sends one) reloads the
page, at most once a minute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqWWDWYeR6E8VJqWwNY7wg
… Cloudflare Access

The reload works for any auth proxy that redirects to its sign-in
(Cloudflare Access, Authelia, Authentik, oauth2-proxy…): nothing in it
checks Cloudflare. The names and comments now say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MqWWDWYeR6E8VJqWwNY7wg
@mathieuletyrant mathieuletyrant changed the title fix(web): sign in again when the Cloudflare Access session ends fix(web): sign in again when an auth proxy's session ends Nov 23, 2026
@mathieuletyrant
mathieuletyrant merged commit 81f659f into main Nov 23, 2026
1 check passed
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.

2 participants