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/clerk.md
1# Clerk23Official docs:45- https://docs.convex.dev/auth/clerk6- https://clerk.com/docs/guides/development/integrations/databases/convex78Use this when the app already uses Clerk or the user wants Clerk's hosted auth9features.1011## Workflow12131. Confirm the user wants Clerk142. Make sure the user has a Clerk account and a Clerk application153. Determine the app framework:16- React17- Next.js18- TanStack Start194. Ask whether the user wants local-only setup or production-ready setup now205. Gather the Clerk keys and the Clerk Frontend API URL216. Follow the correct framework section in the official docs227. Complete the backend and client wiring238. Verify Convex reports the user as authenticated after login249. If the user wants production-ready setup, make sure the production Clerk25config is also covered2627## What To Do2829- Read the official Convex and Clerk guide before writing setup code30- If the user does not already have Clerk set up, send them to31`https://dashboard.clerk.com/sign-up` to create an account and32`https://dashboard.clerk.com/apps/new` to create an application33- Send the user to `https://dashboard.clerk.com/apps/setup/convex` if the Convex34integration is not already active35- Match the guide to the app's framework, usually React, Next.js, or TanStack36Start37- Use the official examples for `ConvexProviderWithClerk`, `ClerkProvider`, and38`useAuth`3940## Key Setup Areas4142- install the Clerk SDK for the framework in use43- configure `convex/auth.config.ts` with the Clerk issuer domain44- set the required Clerk environment variables45- wrap the app with `ClerkProvider` and `ConvexProviderWithClerk`46- use Convex auth-aware UI patterns such as `Authenticated`, `Unauthenticated`,47and `AuthLoading`4849## Files and Env Vars To Expect5051- `convex/auth.config.ts`52- React or Vite client entry such as `src/main.tsx`53- Next.js client wrapper for Convex if using App Router54- Clerk account sign-up page: `https://dashboard.clerk.com/sign-up`55- Clerk app creation page: `https://dashboard.clerk.com/apps/new`56- Clerk Convex integration page: `https://dashboard.clerk.com/apps/setup/convex`57- Clerk API keys page: `https://dashboard.clerk.com/last-active?path=api-keys`58- Clerk environment variables:59- `CLERK_JWT_ISSUER_DOMAIN` for Convex backend validation in the Convex docs60- `CLERK_FRONTEND_API_URL` in the Clerk docs61- `VITE_CLERK_PUBLISHABLE_KEY` for Vite apps62- `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` for Next.js apps63- `CLERK_SECRET_KEY` for Next.js server-side Clerk setup where required6465`CLERK_JWT_ISSUER_DOMAIN` and `CLERK_FRONTEND_API_URL` refer to the same Clerk66Frontend API URL value. Do not treat them as two different URLs.6768## Concrete Steps69701. If needed, create a Clerk account at `https://dashboard.clerk.com/sign-up`712. If needed, create a Clerk application at72`https://dashboard.clerk.com/apps/new`733. Open `https://dashboard.clerk.com/last-active?path=api-keys` and copy the74publishable key, plus the secret key for Next.js where needed754. Open `https://dashboard.clerk.com/apps/setup/convex`765. Activate the Convex integration in Clerk if it is not already active776. Copy the Clerk Frontend API URL shown there787. Install the Clerk package for the app's framework798. Create or update `convex/auth.config.ts` so Convex validates Clerk tokens809. Set the publishable key in the frontend environment8110. Set the issuer domain or Frontend API URL so Convex can validate the JWT8211. Replace plain `ConvexProvider` wiring with `ConvexProviderWithClerk`8312. Wrap the app in `ClerkProvider`8413. Use Convex auth helpers for authenticated rendering8514. Run the normal Convex dev or deploy flow after updating backend auth config8615. If the user wants production-ready setup, configure the production Clerk87values and production issuer domain too8889## Gotchas9091- Prefer `useConvexAuth()` over raw Clerk auth state when deciding whether92Convex-authenticated UI can render93- For Next.js, keep server and client boundaries in mind when creating the94Convex provider wrapper95- After changing `convex/auth.config.ts`, run the normal Convex dev or deploy96flow so the backend picks up the new config97- Do not stop at "Clerk login works". The important check is that Convex also98sees the session and can authenticate requests.99- If the repo already uses Clerk, preserve its existing auth flow unless the100user asked to change it.101- Do not assume the same Clerk values work for both dev and production. Check102the production issuer domain and publishable key separately.103- The Convex setup page is where you get the Clerk Frontend API URL for Convex.104Keep using the Clerk API keys page for the publishable key and the secret key.105- If Convex says no auth provider matched the token, first confirm the Clerk106Convex integration was activated at107`https://dashboard.clerk.com/apps/setup/convex`108- After activating the Clerk Convex integration, sign out completely and sign109back in before retesting. An old Clerk session can keep using a token that110Convex rejects.111112## Production113114- Ask whether the user wants dev-only setup or production-ready setup115- If the answer is production-ready, make sure production Clerk keys and issuer116configuration are included117- Verify production redirect URLs and any production Clerk domain values before118calling the task complete119- Do not silently write a notes file into the repo by default. If the user wants120rollout or handoff docs, create one explicitly.121122## Validation123124- Verify the user can sign in with Clerk125- If the Clerk integration was just activated, verify after a full Clerk126sign-out and fresh sign-in127- Verify `useConvexAuth()` reaches the authenticated state after Clerk login128- Verify protected Convex queries run successfully inside authenticated UI129- Verify `ctx.auth.getUserIdentity()` is non-null in protected backend functions130- If production-ready setup was requested, verify the production Clerk131configuration is also covered132133## Checklist134135- [ ] Confirm the user wants Clerk136- [ ] Ask whether the user wants local-only setup or production-ready setup137- [ ] Follow the correct framework section in the official guide138- [ ] Set Clerk environment variables139- [ ] Configure `convex/auth.config.ts`140- [ ] Verify Convex authenticated state after login141- [ ] If requested, configure the production deployment too142