04
Product
16
Backend
09
Auth
12
iOS
07
Infra
02
Real-Time

Support token and session auth in parallel

ADR-0020 SUPERSEDED · 2025-07-25
Support both token-based and session-based authentication in parallel

Context

After adopting PASETO tokens for transport (ADR-0019), we had token generation working but no token validation middleware. The existing auth stack (tower-sessions, axum-login) handled cookies. We needed both to work — tokens for iOS, cookies for potential future web clients.

Decision

Run token-based and session-based authentication in parallel. Token middleware validates Authorization: Bearer headers and populates auth context. Session middleware handles cookies as before. User::from_ctx() tries token first, falls back to session.

Why it was abandoned

Tower-sessions and axum-login weren't built to support an alternative transport mechanism alongside cookies. Our middleware added an Authorization header check, but the built-in session management was updating, deleting, and managing token values in Redis in ways we didn't anticipate and couldn't control without forking the crates. We got close but it was effectively a monkey-patch. ADR-0028 removed the session layer entirely instead.