Skip to main content

Authentication

Users sign up and sign in with Supabase Auth in the web app. The API never handles passwords; it verifies the access token on each request.

Flow

Verification (app/utils/auth.py)

  • Keys — fetched by kid from {SUPABASE_URL}/auth/v1/.well-known/jwks.json and cached for SUPABASE_JWKS_CACHE_SECONDS. An unseen kid triggers a refetch, so key rotation needs no restart.
  • Algorithms — ES256 and RS256 only. HS256 (legacy shared secret) tokens are rejected: enable asymmetric JWT signing keys in the Supabase project.
  • Claims — exp, sub, aud (= SUPABASE_JWT_AUDIENCE, default authenticated), and iss (= {SUPABASE_URL}/auth/v1) are required.
  • Identity — sub must be a UUID. It becomes AuthUser.id (along with optional AuthUser.email), binds user_id to the request logging context, and scopes user-specific database queries.
The JWKS fetch is blocking HTTP, so get_current_user runs verification in a worker thread.

Using it in a route

Errors