@repo/convex bridges Convex and Clerk in your Next.js app. It wraps ConvexProviderWithClerk so that all Convex queries and mutations run with the user’s Clerk session.
Usage
Wrap your app with the provider in a client component:apps/app/components/convex-client-provider.tsx
apps/app/app/layout.tsx
How Auth Works
The provider passes Clerk’suseAuth hook to Convex. When a user signs in through Clerk, the provider attaches their JWT to every Convex request. Convex validates the token against your Clerk JWT issuer domain (configured in convex/auth.config.ts) and makes the identity available via ctx.auth in your backend functions.
This means every query and mutation in @repo/backend can call ctx.auth.getUserIdentity() to get the current user’s identity without extra setup.
User Sync via Webhooks
Clerk JWTs contain basic identity fields, but your app needs richer user data in Convex for queries, foreign keys, and cross-user lookups. mf² solves this with a pre-built webhook sync. When a user signs up, updates their profile, or deletes their account, Clerk sends a webhook to your Convex HTTP endpoint at/webhooks/clerk. The handler in convex/http.ts validates the signature with Svix, then upserts or deletes the user record in Convex:
packages/backend/convex/http.ts
users table stores the full Clerk user object and indexes by clerkUser.id for fast lookups. Deleting a user cascades to remove their threads, messages, and settings.
Configure the webhook in Clerk
- Go to Webhooks in the Clerk dashboard and click + Add Endpoint.
- Set the endpoint URL to
https://<your-deployment>.convex.site/webhooks/clerk(note:.site, not.cloud). - Under Message Filtering, select all user events.
- Copy the Signing Secret (starts with
whsec_) and set it asCLERK_WEBHOOK_SECRETin your Convex dashboard environment variables.
Querying user data
Use the helpers inconvex/auth/users.ts to access the current user in your backend functions:
packages/backend/convex/chat/streaming.ts
HTTP Client
For server-side Convex calls outside of React, use the HTTP client:apps/app/lib/convex.ts