Skip to content

Fix: recover an admin session that expired mid-edit - #40

Merged
SandObserver merged 1 commit into
mainfrom
fix/recover-expired-session
Aug 12, 2026
Merged

SandObserver merged 1 commit into
mainfrom
fix/recover-expired-session

Conversation

@SandObserver

Copy link
Copy Markdown
Owner

Summary

  • Add recoversSession to admin-logic.js: a 401, excluding /api/auth/check and /api/auth/login, which are the requests signing in is made of.
  • Intercept that case in ag and ap, raise the sign-in overlay through a registered handler, and reissue the request once, so the interrupted save completes itself.
  • Share one sign-in between requests that fail together, since saveServer makes three writes in a row and each would otherwise raise its own overlay.
  • Export requireLogin from admin-auth.js, resolving when the existing login screen reports success; the screen is position:fixed, so the editor underneath keeps its contents.
  • Register the handler in admin.js rather than importing it into admin-shared.js, which the sign-in screen itself depends on.

Testing
All green. Added 12 tests: 7 driving the real retry path against a stubbed fetch (retry, no-loop, decline, shared sign-in, auth-path exclusion) and 5 on the rule.

Checklist

  • Stays within the project constraints: one container, no runtime dependencies, no build step (see CONTRIBUTING.md).
  • Tests added or updated for new logic, and the full suite, lint, and typechecks pass.
  • Docs updated if behavior or configuration changed.
  • CHANGELOG.md updated under Unreleased if the change is user-visible.

An expired session surfaced as "Save failed: Unauthorised" on every attempt,
with no route back to signing in. The only way out was reloading the page,
which discarded whatever was in the editor at the time, and nothing on screen
said that was what had happened.

Intercept a 401 in ag and ap, the two helpers every admin read and write goes
through, raise the sign-in overlay, and reissue the request once the session is
back. The overlay is fixed positioning over the page, so a half-filled editor
survives the interruption untouched.

The rule is recoversSession: only a 401, and never from the two requests that
signing in is made of, which would put a sign-in box on top of a sign-in box.
An upstream service answering 401 arrives as a 502 carrying that status in its
detail, so a failing badge does not raise one.

One sign-in is shared between requests that fail together, since a settings
save makes three writes in a row, and a retry is never itself retried.
@SandObserver SandObserver added the bug Something isn't working label Aug 12, 2026
@SandObserver
SandObserver merged commit 6e3ee15 into main Aug 12, 2026
4 checks passed
@SandObserver
SandObserver deleted the fix/recover-expired-session branch August 12, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant