docs: specify session expiry recovery
This commit is contained in:
1 parent
a98c7bc8ee
commit
56f21a5289
1 file changed
+62
@@ -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.
|
||||
Reference in new issue
Block a user