Self-Hosting
Clerk Setup
Step-by-step guide to using Clerk as your identity provider with Kaiten.
Clerk Setup Guide
Clerk is the recommended identity provider for Kaiten. This guide walks you through the complete setup.
Create a Clerk Application
- Go to clerk.com and create an account
- Create a new application
- Enable Organizations in Settings → Organizations
Get Your API Keys
In your Clerk dashboard, go to API Keys and copy:
- Secret Key:
sk_test_xxxxxorsk_live_xxxxx - Publishable Key:
pk_test_xxxxxorpk_live_xxxxx
Configure Environment Variables
Add to your .env file:
CLERK_SECRET_KEY=sk_test_xxxxx
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxxxxConfigure JWT Validation in Traefik
The compose.yml already includes the Clerk JWT middleware configuration. Verify these labels on your Traefik service:
- "traefik.http.middlewares.clerk-jwt.plugin.jwt.Keys.0.URL=https://${CLERK_DOMAIN}/.well-known/jwks.json"
- "traefik.http.middlewares.clerk-jwt.plugin.jwt.Alg=RS256"
- "traefik.http.middlewares.clerk-jwt.plugin.jwt.Issuers=https://${CLERK_DOMAIN}"The CLERK_DOMAIN is automatically derived from your Clerk application. It typically looks like xxxxx.clerk.accounts.dev.
Configure Clerk Webhooks
Kaiten syncs organizations and users from Clerk via webhooks:
- In Clerk Dashboard → Webhooks → Add Endpoint
- Set URL:
https://your-kaiten-domain/api/webhooks/clerk - Select events:
organization.createdorganization.updatedorganization.deleteduser.createduser.updatedorganizationMembership.createdorganizationMembership.updatedorganizationMembership.deleted
- Copy the signing secret → add to
.envasCLERK_WEBHOOK_SECRET
Test the Integration
- Start Kaiten:
make up - Open the dashboard:
http://localhost:6000 - You should see the Clerk sign-in page
- After signing in, your organization and user profile are synced automatically
How Clerk Auth Flows in Kaiten
- User signs in via Clerk → receives a session JWT
- Frontend sends JWT in
Authorization: Bearerheader - Traefik validates the JWT against Clerk's JWKS endpoint
- API extracts Principal from JWT claims (
user_id,org_id, scopes) - All database queries are scoped to the organization

