Athena ERP uses JWT-based authentication powered by Supabase. All API endpoints (except public ones) require a valid Bearer token in the Authorization header.The authentication system provides:
JWT token validation with Supabase integration
Multi-tenant school context via X-School-Id header
Role-based permissions (RBAC) at the code level
School membership verification against the local database
Athena accepts JWTs issued by Supabase with the following claims:
Claim
Type
Description
sub
string
User ID (UUID format)
email
string
User’s email address
iss
string
Issuer (Supabase auth URL)
app_metadata.school_id
string (optional)
Suggested school context
app_metadata.roles
array (optional)
JWT-level roles
The app_metadata roles are suggestions. The actual authorization is resolved against the local database using school_memberships table. This ensures the database is the source of truth.
If a user has multiple school memberships and no X-School-Id header is provided, the API will return a 400 Bad Request error unless the user has the manage:schools permission (superadmin).
The JWT decoder never infers the Supabase URL from the token itself. It only uses the server-configured SUPABASE_URL to prevent Server-Side Request Forgery attacks.
Required environment variables for authentication:
# JWT Configuration (must match Supabase project)JWT_SECRET=your-supabase-jwt-secretJWT_ALGORITHM=HS256ACCESS_TOKEN_EXPIRE_MINUTES=30# Supabase IntegrationSUPABASE_URL=https://your-project.supabase.coSUPABASE_ANON_KEY=your-anon-keySUPABASE_SERVICE_ROLE_KEY=your-service-role-key
In development, the JWT_SECRET defaults to super-secret-local-dev-key-change-in-prod. Always use a secure secret in production that matches your Supabase project settings.