Skip to content

Web: a sign-out counts only when the BFF confirms it - #105

Merged
dszp merged 2 commits into
devfrom
fix/web-logout-confirm
Nov 29, 2026
Merged

dszp merged 2 commits into
devfrom
fix/web-logout-confirm

Conversation

@dszp

@dszp dszp commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #104 from its final review, before production.

  • logout() reads the BFF's answer by the same rule as the pending-sign-out retry (logoutOutcome in session.ts), with redirect: "manual":

    • a 204 or a 401 signed_out ends the session;
    • any other 4xx or 5xx is a refusal, and the page stays signed in;
    • a redirect, or another page's 2xx, isn't the BFF's answer: this device's data goes and the sign-out stays pending.

    Before this change, a 200 from something other than the BFF ended the session with nothing pending. The session cookie could then sign the browser straight back in.

  • Sign out after an expired session marks the sign-out pending and deletes this device's data at once, alongside the logout request, instead of after it.

  • The manifest link carries crossorigin="use-credentials". Without cookies, a manifest fetch behind Cloudflare Access gets the sign-in redirect and the app can't install. Potem Server spotted this on web-dev.

  • idb-storage.ts imports DEADLINES_META instead of repeating the string.

  • Sign out is pending from the moment it starts (second commit, from the PR review): signOut() set the pending mark only after the request answered, so a tab closed mid-request (up to 30 s) left a live cookie and nothing pending. It is now set before the request and cleared by a confirmed answer or a refusal. Sign out on a page whose session already expired goes through discardSaved().

Tests: 5 new (logout redirect mode, 401 signed_out, opaque redirect, a non-BFF 200, and a discard that doesn't wait on the request) plus a build test for the manifest attribute; each failed first. The test fake's logout now answers 204, as the real BFF does. pnpm test exit 0 (3684), five typechecks and leak-guard clean.

🤖 Generated with Claude Code

dszp and others added 2 commits November 29, 2026 17:21
logout() now sends POST /auth/logout with redirect: manual and reads the
answer by the same rule as the pending-sign-out retry (logoutOutcome): a
204 or a 401 signed_out ends the session; any other 4xx or 5xx is a
refusal and the page stays signed in; a redirect or another page's 2xx
isn't the BFF's answer, so this device's data goes and the sign-out
stays pending, as when there is no answer.

Sign out after an expired session marks the sign-out pending and deletes
this device's data at once, alongside the logout request, so a slow
request can't leave the data on disk and a closed tab can't forget the
server session may still be open.

The manifest link carries crossorigin="use-credentials": a browser
fetches the manifest without cookies otherwise, and behind Cloudflare
Access that fetch gets the sign-in redirect. idb-storage imports
DEADLINES_META rather than repeating the name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
signOut() set the pending-logout mark only after the request answered,
up to the 30 s timeout. A tab closed in that window left a live cookie,
the database not yet deleted and nothing pending, so the next visit was
signed in with the data intact. The mark is now set before the request
and cleared by a confirmed answer or a refusal (which leaves the page
signed in). signOut() on a page whose session already expired goes
through discardSaved(), since logout() would do nothing there.

Tests: a logoutOutcome table, the pending mark during the request, a
refused sign-out clearing it, Sign out after an expiry, discardSaved
clearing pending after a 204; the close() test's fake answers 204.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dszp
dszp merged commit d0dda14 into dev Nov 29, 2026
2 checks passed
@dszp
dszp deleted the fix/web-logout-confirm branch November 29, 2026 22:27
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.

1 participant