All authentication is centralized in route-generator.ts. Each route explicitly declares its auth type at definition time using one of 6 factory functions.
| Type | Factory Function | Auth Header | Use Case |
|---|---|---|---|
| PUBLIC | getPublicPath | None | Login, signup, public data |
| USER | getUserAuthPath | authorization | Standard authenticated endpoints |
| RESTRICTED | getRestrictedUserAuthPath | authorization + whitelist | Beta, premium features |
| ADMIN | getAdminAuthPath | custom-admin-auth | Diagnostics, config, cache |
| BACKEND | getBackendAuthPath | internal-auth | Service-to-service (Kafka) |
| API KEY | getRestrictedUser...AllowedKeys | authorization or x-print-api-key | Buy/sell tokens via API key |
noAuthRequiredPreHandler
No authentication required. Sets request.user = { id: '' } with an empty ID. Includes mock handler support for testing.
authUserPreHandler
Standard JWT authentication. Requires authorization header with a Firebase ID token. Also accepts custom-admin-auth for Postman testing. Validates via AuthService.validateToken() and sets request.user = { id: userId }.
restrictedAuthUserPreHandler
JWT + UID whitelist. Same as getUserAuthPath plus checks Firebase settings: restrictByUid and allowedUids. Blocks non-whitelisted users even if they have a valid token.
authAdminPreHandler
Admin-only operations. Requires custom-admin-auth header matching PrintConstants.ADMIN_AUTH_KEY. Controlled by Firebase setting allowAdminKeyFromPostman. No JWT needed.
backendAuthPreHandler
Service-to-service communication. Requires internal-auth header matching PrintConstants.INTERNAL_ENDPOINTS_AUTH_KEY. For internal Kafka processors and orchestrators. Not exposed to external clients.
restrictedAuthUserApiKeyPreHandler
Dual authentication: supports JWT OR x-print-api-key header. Checks UID whitelist when enabled. Includes an onSend hook for API key usage logging.
Key Format
pk_live_... / pk_test_...
Security
SHA-256 hash, timing-safe compare
custom-admin-auth headerauthorization headerauthorizationx-print-api-keyApiKeyServicerequest.apiKeyContextReal-time Firebase-backed settings at /api-settings that control auth behavior. Hot-reloads on changes.
Enable admin key testing
Enable UID whitelist
Whitelisted user IDs
Feature flag