Authentication
API authentication methods.
API Key (server-to-server)
Used by the PHP backend and other internal services. The key is set via the API_KEY environment variable.
curl -H "X-API-Key: your-secret-key" https://api.example.com/api/deals/abc-123All /api/deals/* routes require a valid API key. Requests without it or with an invalid key receive a 401 Unauthorized response.
JWT Bearer (client-side)
Used by the web application for authenticated user actions. Tokens are issued by Clerk.
curl -H "Authorization: Bearer eyJhbG..." https://api.example.com/api/protected/resourceTwo middlewares share the work:
- The identity middleware runs on every route and never refuses a request. It verifies the Bearer with
verifyTokenfrom@workspace/auth/serverand setsauth({ userId, email }) on the request context, ornullwhen the header is absent, malformed, invalid or expired. requireAuthguards the protected routers: it answers401 Unauthorizedwhenauthisnull, then setsuserIdanduserEmail. An optionalX-BT-Impersonationheader lets an admin act as another account; see Impersonation.
A public route reads auth without requiring it. A deal read with the API key, for instance, names the player behind a Bearer to decide who pays the serve, and reads as an anonymous player for any token that names no account.
Public routes
Some endpoints (e.g. form submissions) require no authentication. These are rate-limited and validated via request schemas instead.