ADR 0003: M2 reviewer sessions and read-only inbox
- Status: Accepted
- Date: 2026-11-24
- Deciders: AP Dev Solutions, LLC
- Related: the project overview §9, §11, §14 (M2),
docs/adr/0001-stack.md,docs/adr/0002-m1-capture-api.md,openspec/changes/m2-readonly-inbox/design.md
Context
Section titled “Context”M1 authenticated capture clients with bearer API keys and exposed read endpoints to those keys as a temporary bridge. The office needs a browser inbox with reviewer identity, a secure session, and no API key in the browser. Review actions are a later M2 slice, so this decision covers login, sessions, and read-only inbox access.
Decisions
Section titled “Decisions”Magic links are single-use, hashed, and short-lived
Section titled “Magic links are single-use, hashed, and short-lived”POST /v1/auth/magic-link creates a 32-byte token, stores only its SHA-256 hash, and expires it after
15 minutes. Verification atomically marks the token used. The email lookup assumes one active account
per email for this single-tenant-local slice; hosted multi-tenant login will need a tenant hint.
The local EmailSender adapter logs the link. Outside production, the API also returns the link as
devLink so local testing does not require an email provider. Production requires a real sender.
Sessions are server-side and cookie-backed
Section titled “Sessions are server-side and cookie-backed”A session is a 32-byte token whose hash is stored in sessions, with a seven-day expiry and a
revocation timestamp. The browser receives the raw token in cd_session:
HttpOnlySameSite=LaxPath=/Max-Age=604800SecurewhenENVIRONMENT=production
Logout revokes the row and clears the cookie. Cookie-authenticated state changes also require the
request Origin to match WEB_BASE_URL.
Read endpoints accept a session or an API key
Section titled “Read endpoints accept a session or an API key”Towns, parcels, capture list, and capture detail use a combined read middleware. A valid session wins; otherwise an API key is accepted for capture clients and tests. Both resolve to the same tenant id, so the core use cases and repositories remain unchanged.
Uploads and capture submission remain API-key only. /v1/me and logout are session-only.
The first web inbox is read-only
Section titled “The first web inbox is read-only”The SPA uses hash routes (#/login, #/, #/captures/:id) and TanStack Query. The login screen
requests a magic link, the list supports status/town/type filters, and detail shows payload,
attachments, and audit events. No accept/return/reject/request-information controls exist in this
slice.
Hash routing avoids server rewrite configuration until deployment work.
Consequences
Section titled “Consequences”- Session and magic-link tables require an M2 migration; capture and attachment tables are unchanged.
- Hosted multi-tenant login needs a tenant hint or organization-specific login URL before real use.
- Review actions will reuse
requireSessionand add CSRF tokens before state-changing review routes. - Expired session rows accumulate until M3 retention/cleanup work.
- Local login is intentionally convenient: the development link is returned by the API outside production.