From 56f21a528953533e3873c958bd8665e59d024f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Tue, 11 Aug 2026 17:06:23 +0200 Subject: [PATCH] docs: specify session expiry recovery --- ...ession-expiry-and-error-recovery-design.md | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 docs/superpowers/specs/2026-08-11-session-expiry-and-error-recovery-design.md diff --git a/docs/superpowers/specs/2026-08-11-session-expiry-and-error-recovery-design.md b/docs/superpowers/specs/2026-08-11-session-expiry-and-error-recovery-design.md new file mode 100644 index 0000000..b2222dd --- /dev/null +++ b/docs/superpowers/specs/2026-08-11-session-expiry-and-error-recovery-design.md @@ -0,0 +1,62 @@ +# Session Expiry and Error Recovery Design + +## Goal + +Refreshing a protected page after the session expires must not produce the +generic Next.js server error screen. Users must be returned to the existing +sign-in page, while genuine unexpected rendering failures receive a branded +recovery screen. + +## Root Cause + +The admin and editorial layouts call principal guards during server rendering. +An expired session causes `PrincipalAuthorizationError` with code +`AUTHENTICATION_REQUIRED`. Neither protected layout handles this expected +state, and the application has no route-level `error.tsx`, so Next.js renders +its generic production error page. + +## Expected Authentication Handling + +A small server-only page-access boundary executes the existing principal guard. +It handles only `PrincipalAuthorizationError("AUTHENTICATION_REQUIRED")` by +calling `redirect("/anmelden")`. Every other authorization or infrastructure +error is rethrown unchanged. + +Both `src/app/admin/layout.tsx` and `src/app/redaktion/layout.tsx` use this +boundary. API routes retain their existing HTTP error behavior. Authentication, +session duration and account status rules are not changed. + +## Unexpected Error Recovery + +`src/app/error.tsx` provides a client-side route error boundary for unexpected +rendering failures below the root layout. It follows the portal's black-and- +white visual language and contains: + +- the heading `Diese Seite konnte nicht geladen werden.`; +- a short instruction to retry or sign in again; +- `Erneut versuchen`, which invokes Next.js' supplied `reset()` callback; +- `Zur Anmeldung`, which navigates directly to `/anmelden`. + +The page does not expose stack traces, database errors or the Next.js error +digest. It does not turn authorization failures other than an expired session +into login redirects; those remain visible as unexpected failures for diagnosis. + +## Verification + +Automated tests prove that: + +- an expired page session redirects exactly to `/anmelden`; +- non-authentication errors are rethrown; +- the error boundary renders both recovery controls; +- `Erneut versuchen` calls `reset()` once; +- `Zur Anmeldung` links exactly to `/anmelden`. + +The complete deterministic suite, typecheck, lint and production build must +remain green. No database migration or new dependency is required. + +## Out of Scope + +- Changing session expiry duration. +- Automatically retrying database or Immich failures. +- Changing API response status codes. +- Creating a separate public home-page recovery action.