Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Set up Convex authentication with Convex Auth, Clerk, WorkOS AuthKit, Auth0, or custom JWT providers.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/workos-authkit.md
1# WorkOS AuthKit23Official docs:45- https://docs.convex.dev/auth/authkit/6- https://docs.convex.dev/auth/authkit/add-to-app7- https://docs.convex.dev/auth/authkit/auto-provision89Use this when the app already uses WorkOS or the user wants AuthKit10specifically.1112## Workflow13141. Confirm the user wants WorkOS AuthKit152. Determine whether they want:16- a Convex-managed WorkOS team17- an existing WorkOS team183. Ask whether the user wants local-only setup or production-ready setup now194. Read the official Convex and WorkOS AuthKit guide205. Create or update `convex.json` for the app's framework and real local port216. Follow the correct branch of the setup flow based on that choice227. Configure the required WorkOS environment variables238. Configure `convex/auth.config.ts` for WorkOS-issued JWTs249. Wire the client provider and callback flow2510. Verify authenticated requests reach Convex2611. If the user wants production-ready setup, make sure the production WorkOS27configuration is covered too2812. Only add `storeUser` or a `users` table if the app needs first-class user29rows inside Convex3031## What To Do3233- Read the official Convex and WorkOS AuthKit guide before writing setup code34- Determine whether the user wants a Convex-managed WorkOS team or an existing35WorkOS team36- Treat `convex.json` as a first-class part of the AuthKit setup, not an37optional extra38- Follow the current setup flow from the docs instead of relying on older39examples4041## Key Setup Areas4243- package installation for the app's framework44- `convex.json` with the `authKit` section for dev, and preview or prod if45needed46- environment variables such as `WORKOS_CLIENT_ID`, `WORKOS_API_KEY`, and47redirect configuration48- `convex/auth.config.ts` wiring for WorkOS-issued JWTs49- client provider setup and token flow into Convex50- login callback and redirect configuration5152## Files and Env Vars To Expect5354- `convex.json`55- `convex/auth.config.ts`56- frontend auth provider wiring57- callback or redirect route setup where the framework requires it58- WorkOS environment variables commonly include:59- `WORKOS_CLIENT_ID`60- `WORKOS_API_KEY`61- `WORKOS_COOKIE_PASSWORD`62- `VITE_WORKOS_CLIENT_ID`63- `VITE_WORKOS_REDIRECT_URI`64- `NEXT_PUBLIC_WORKOS_REDIRECT_URI`6566For a managed WorkOS team, `convex dev` can provision the AuthKit environment67and write local env vars such as `VITE_WORKOS_CLIENT_ID` and68`VITE_WORKOS_REDIRECT_URI` into `.env.local` for Vite apps.6970## Concrete Steps71721. Choose Convex-managed or existing WorkOS team732. Create or update `convex.json` with the `authKit` section for the framework74in use753. Make sure the dev `redirectUris`, `appHomepageUrl`, `corsOrigins`, and local76redirect env vars match the app's actual local port774. For a managed WorkOS team, run `npx convex dev` and follow the interactive78onboarding flow795. For an existing WorkOS team, get `WORKOS_CLIENT_ID` and `WORKOS_API_KEY` from80the WorkOS dashboard and set them with `npx convex env set`816. Create or update `convex/auth.config.ts` for WorkOS JWT validation827. Run the normal Convex dev or deploy flow so backend config is synced838. Wire the WorkOS client provider in the app849. Configure callback and redirect handling8510. Verify the user can sign in and return to the app8611. Verify Convex sees the authenticated user after login8712. If the user wants production-ready setup, configure the production client88ID, API key, redirect URI, and deployment settings too8990## Gotchas9192- The docs split setup between Convex-managed and existing WorkOS teams, so ask93which path the user wants if it is not obvious94- Keep dev and prod WorkOS configuration separate where the docs call for95different client IDs or API keys96- Only add `storeUser` or a `users` table if the app needs first-class user rows97inside Convex98- Do not mix dev and prod WorkOS credentials or redirect URIs99- If the repo already contains WorkOS setup, preserve the current tenant model100unless the user wants to change it101- For managed WorkOS setup, `convex dev` is interactive the first time. In102non-interactive terminals, stop and ask the user to complete the onboarding103prompts.104- `convex.json` is not optional for the managed AuthKit flow. It drives redirect105URI, homepage URL, CORS configuration, and local env var generation.106- If the frontend starts on a different port than the one in `convex.json`, the107hosted WorkOS sign-in flow will point to the wrong callback URL. Update108`convex.json`, update the local redirect env var, and run `npx convex dev`109again.110- Vite can fall off `5173` if other apps are already running. Do not assume the111default port still matches the generated AuthKit config.112- A successful WorkOS sign-in should redirect back to the local callback route113and then reach a Convex-authenticated state. Do not stop at "the hosted WorkOS114page loaded."115116## Production117118- Ask whether the user wants dev-only setup or production-ready setup119- If the answer is production-ready, make sure the production WorkOS client ID,120API key, redirect URI, and Convex deployment config are all covered121- Verify the production redirect and callback settings before calling the task122complete123- Do not silently write a notes file into the repo by default. If the user wants124rollout or handoff docs, create one explicitly.125126## Validation127128- Verify the user can complete the login flow and return to the app129- Verify the callback URL matches the real frontend port in local dev130- Verify Convex receives authenticated requests after login131- Verify `convex.json` matches the framework and chosen WorkOS setup path132- Verify `convex/auth.config.ts` matches the chosen WorkOS setup path133- Verify environment variables differ correctly between local and production134where needed135- If production-ready setup was requested, verify the production WorkOS136configuration is also covered137138## Checklist139140- [ ] Confirm the user wants WorkOS AuthKit141- [ ] Ask whether the user wants local-only setup or production-ready setup142- [ ] Choose Convex-managed or existing WorkOS team143- [ ] Create or update `convex.json`144- [ ] Configure WorkOS environment variables145- [ ] Configure `convex/auth.config.ts`146- [ ] Verify authenticated requests reach Convex after login147- [ ] If requested, configure the production deployment too148