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/convex-auth.md
1# Convex Auth23Official docs: https://docs.convex.dev/auth/convex-auth Setup guide:4https://labs.convex.dev/auth/setup56Use this when the user wants auth handled directly in Convex rather than through7a third-party provider.89## Workflow10111. Confirm the user wants Convex Auth specifically122. Determine which sign-in methods the app needs:13- magic links or OTPs14- OAuth providers15- passwords and password reset163. Ask whether the user wants local-only setup or production-ready setup now174. Read the Convex Auth setup guide before writing code185. Make sure the project has a configured Convex deployment:19- run `npx convex dev` first if `CONVEX_DEPLOYMENT` is not set20- if CLI configuration requires interactive human input, stop and ask the21user to complete that step before continuing226. Install the auth packages:23- `npm install @convex-dev/auth @auth/[email protected]`247. Run the initialization command:25- `npx @convex-dev/auth`268. Confirm the initializer created:27- `convex/auth.config.ts`28- `convex/auth.ts`29- `convex/http.ts`309. Add the required `authTables` to `convex/schema.ts`3110. Replace plain `ConvexProvider` wiring with `ConvexAuthProvider`3211. Configure at least one auth method in `convex/auth.ts`3312. Run `npx convex dev --once` or the normal dev flow to push the updated34schema and generated code3513. Verify the client can sign in successfully3614. Verify Convex receives authenticated identity in backend functions3715. If the user wants production-ready setup, make sure the same auth setup is38configured for the production deployment as well3916. Only add a `users` table and `storeUser` flow if the app needs app-level40user records inside Convex4142## What This Reference Is For4344- choosing Convex Auth as the default provider for a new Convex app45- understanding whether the app wants magic links, OTPs, OAuth, or passwords46- keeping the setup provider-specific while using the official Convex Auth docs47for identity and authorization behavior4849## What To Do5051- Read the Convex Auth setup guide before writing setup code52- Follow the setup flow from the docs rather than recreating it from memory53- If the app is new, consider starting from the official starter flow instead of54hand-wiring everything55- Treat `npx @convex-dev/auth` as a required initialization step for existing56apps, not an optional extra5758## Concrete Steps59601. Install `@convex-dev/auth` and `@auth/[email protected]`612. Run `npx convex dev` if the project does not already have a configured62deployment633. If `npx convex dev` blocks on interactive setup, ask the user explicitly to64finish configuring the Convex deployment654. Run `npx @convex-dev/auth`665. Confirm the generated auth setup is present before continuing:67- `convex/auth.config.ts`68- `convex/auth.ts`69- `convex/http.ts`706. Add `authTables` to `convex/schema.ts`717. Replace `ConvexProvider` with `ConvexAuthProvider` in the app entry728. Configure the selected auth methods in `convex/auth.ts`739. Run `npx convex dev --once` or the normal dev flow so the updated schema and74auth files are pushed7510. Verify login locally7611. If the user wants production-ready setup, repeat the required auth77configuration against the production deployment7879## Expected Files and Decisions8081- `convex/schema.ts`82- frontend app entry such as `src/main.tsx` or the framework-equivalent provider83file84- generated Convex Auth setup produced by `npx @convex-dev/auth`85- an existing configured Convex deployment, or the ability to create one with86`npx convex dev`87- `convex/auth.ts` starts with `providers: []` until the app configures actual88sign-in methods8990- Decide whether the user is creating a new app or adding auth to an existing91app92- For a new app, prefer the official starter flow instead of rebuilding setup by93hand94- Decide which auth methods the app needs:95- magic links or OTPs96- OAuth providers97- passwords98- Decide whether the user wants local-only setup or production-ready setup now99- Decide whether the app actually needs a `users` table inside Convex, or100whether provider identity alone is enough101102## Gotchas103104- Do not assume a specific sign-in method. Ask which methods the app needs105before wiring UI and backend behavior.106- `npx @convex-dev/auth` is important because it initializes the auth setup,107including the key material. Do not skip it when adding Convex Auth to an108existing project.109- `npx @convex-dev/auth` will fail if the project does not already have a110configured `CONVEX_DEPLOYMENT`.111- `npx convex dev` may require interactive setup for deployment creation or112project selection. If that happens, ask the user explicitly for that human113step instead of guessing.114- `npx @convex-dev/auth` does not finish the whole integration by itself. You115still need to add `authTables`, swap in `ConvexAuthProvider`, and configure at116least one auth method.117- A project can still build even if `convex/auth.ts` still has `providers: []`,118so do not treat a successful build as proof that sign-in is fully configured.119- Convex Auth does not mean every app needs a `users` table. If the app only120needs authentication gates, `ctx.auth.getUserIdentity()` may be enough.121- If the app is greenfield, starting from the official starter flow is usually122better than partially recreating it by hand.123- Do not stop at local dev setup if the user expects production-ready auth. The124production deployment needs the auth setup too.125- Keep provider-specific setup and Convex Auth authorization behavior in the126official docs instead of inventing shared patterns from memory.127128## Production129130- Ask whether the user wants dev-only setup or production-ready setup131- If the answer is production-ready, make sure the auth configuration is applied132to the production deployment, not just the dev deployment133- Verify production-specific redirect URLs, auth method configuration, and134deployment settings before calling the task complete135- Do not silently write a notes file into the repo by default. If the user wants136rollout or handoff docs, create one explicitly.137138## Human Handoff139140If `npx convex dev` or deployment setup requires human input:141142- stop and explain exactly what the user needs to do143- say why that step is required144- resume the auth setup immediately after the user confirms it is done145146## Validation147148- Verify the user can complete a sign-in flow149- Offer to validate sign up, sign out, and sign back in with the configured auth150method151- If browser automation is available in the environment, you can do this152directly153- If browser automation is not available, give the user a short manual154validation checklist instead155- Verify `ctx.auth.getUserIdentity()` returns an identity in protected backend156functions157- Verify protected UI only renders after Convex-authenticated state is ready158- Verify environment variables and redirect settings match the current app159environment160- Verify `convex/auth.ts` no longer has an empty `providers: []` configuration161once the app is meant to support real sign-in162- Run `npx convex dev --once` or the normal dev flow after setup changes and163confirm Convex codegen and push succeed164- If production-ready setup was requested, verify the production deployment is165also configured correctly166167## Checklist168169- [ ] Confirm the user wants Convex Auth specifically170- [ ] Ask whether the user wants local-only setup or production-ready setup171- [ ] Ensure a Convex deployment is configured before running auth172initialization173- [ ] Install `@convex-dev/auth` and `@auth/[email protected]`174- [ ] Run `npx convex dev` first if needed175- [ ] Run `npx @convex-dev/auth`176- [ ] Confirm `convex/auth.config.ts`, `convex/auth.ts`, and `convex/http.ts`177were created178- [ ] Follow the setup guide for package install and wiring179- [ ] Add `authTables` to `convex/schema.ts`180- [ ] Replace `ConvexProvider` with `ConvexAuthProvider`181- [ ] Configure at least one auth method in `convex/auth.ts`182- [ ] Run `npx convex dev --once` or the normal dev flow after setup changes183- [ ] Confirm which sign-in methods the app needs184- [ ] Verify the client can sign in and the backend receives authenticated185identity186- [ ] Offer end-to-end validation of sign up, sign out, and sign back in187- [ ] If requested, configure the production deployment too188- [ ] Only add extra `users` table sync if the app needs app-level user records189