Repository navigation
fix(web): sign in again when an auth proxy's session ends - #105
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
sw.js, cachesnug-v4): a navigation is now fetched as it is, instead of as a newRequest("/"). The answer is still saved as the app shell, and the cached shell is only served when the network fails.api(): calls are sent withredirect: "manual". A redirect reloads the page (at most once a minute) and is reported as anApiErrorwith 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
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.Checks
bun run typecheckandbun testpass. 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