Overview
Dakora supports multiple authentication methods to protect your API endpoints and manage access control:- API Key Authentication — for programmatic access and integrations (recommended for server‑to‑server)
- JWT Authentication (Clerk) — for browser and user‑initiated flows
- Development Mode — no authentication (local development only)
- API Key via
X-API-Key - JWT Bearer via
Authorization: Bearer <token> - No‑auth (only when
AUTH_REQUIRED=false)
Authentication Modes
Production Mode (Auth Enabled)
WhenAUTH_REQUIRED=true:
- All API endpoints require valid auth
- Multi‑tenant scoping applies (user/workspace/project)
- Unauthorized requests return
401/403
Development Mode (No Auth)
WhenAUTH_REQUIRED=false:
- Endpoints are public (no headers required)
- Intended for local development only
- Requests are scoped to a default project
Frontend Setup (Clerk JWT)
Createstudio/.env.local:
Backend Setup
Set environment variables in your backend.env or deployment:
API Key Authentication (Project‑Scoped)
Generate API Keys
- Web App
- API (JWT required)
Use Settings → API Keys to create a project API key. Keys are shown once; copy and store securely.
Use API Keys
First, resolve your default project with your API key:project_id:
Manage API Keys (CRUD)
API Key Best Practices
Store Keys Securely
Store Keys Securely
Never commit API keys to version control. Use environment variables:Access in code:
Rotate Keys Regularly
Rotate Keys Regularly
Generate new keys periodically and revoke old ones to maintain security.
Use Separate Keys
Use Separate Keys
Create different API keys for different services or environments (dev, staging, production).
Monitor Usage
Monitor Usage
Track which API keys are being used and when. Disable unused keys.
Scope to Projects
Scope to Projects
Limit API keys to specific projects when possible to reduce blast radius if compromised.
JWT Authentication (Clerk)
How It Works
- User Signs In - User authenticates with Clerk
- JWT Generated - Clerk issues a JWT token
- Token Sent - Frontend adds token to request headers
- Token Verified - Backend verifies JWT signature with Clerk’s public key
- Request Processed - If valid, request is processed with user context
Making Authenticated Requests
The frontend automatically handles JWT injection via thecreateApiClient() function:
Session Persistence
Clerk SDK automatically handles session persistence:
- Tokens stored securely in localStorage
- Tokens refreshed before expiration
- Session restored on page reload
- Works across browser tabs
Error Handling
401 Unauthorized
- Verify your API key is correct (if using API key auth)
- Check that your JWT token hasn’t expired (if using Clerk)
- Ensure
X-API-KeyorAuthorizationheader is set - Verify
AUTH_REQUIREDistruein backend configuration
403 Forbidden
- Verify you have access to the project
- Check that the resource belongs to your project scope
- Ensure your user role has appropriate permissions
Multi-Tenancy & Scoping
When authentication is enabled, requests are scoped by:- User ID - From JWT token (Clerk) or API key owner
- Project ID - Stored with user or API key
- Users only see their own templates and resources
- Projects are isolated by default
- Cross-tenant access is prevented automatically
Testing with Authentication
Using TestClient (Backend)
Using cURL (Manual)
Troubleshooting
Frontend shows 'Authenticate' but no sign-in modal
Frontend shows 'Authenticate' but no sign-in modal
Issue: Clerk not configured properlySolution:
- Verify
VITE_CLERK_PUBLISHABLE_KEYis set instudio/.env.local - Ensure key is correct (check Clerk dashboard)
- Restart dev server:
npm run dev
API requests return 401 Unauthorized
API requests return 401 Unauthorized
Can't access own templates after login
Can't access own templates after login
Issue: Multi-tenancy scoping issueSolution:
- Verify database stores templates under user scope
- Check user ID matches between frontend and backend
- Ensure project ID is properly set in Clerk custom claims
Backend doesn't validate Clerk tokens
Backend doesn't validate Clerk tokens
Issue:
CLERK_JWT_ISSUER or CLERK_JWKS_URL not setSolution:- Get values from Clerk dashboard
- Set in backend
.env - Restart backend server