This guide covers the universal setup steps that apply to every framework. After completing them, follow your framework-specific guide to finish the remaining configuration.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/get-convex/better-auth/llms.txt
Use this file to discover all available pages before exploring further.
You need an existing Convex project before starting. Run
npm create convex@latest if you don’t have one, then come back here.Start the Convex dev server
Keep
npx convex dev running throughout this setup. It initializes your deployment if it doesn’t exist yet, and keeps generated types current as you add files.Install packages
Install the component, ensure you have the latest version of Convex, and install a pinned version of Better Auth.
Register the component
Register the Better Auth component in your Convex project configuration.
convex/convex.config.ts
Add Convex auth config
Add a
convex/auth.config.ts file to configure Better Auth as a Convex authentication provider. This is what tells Convex to trust JWTs issued by the component.convex/auth.config.ts
Set environment variables
Generate a secret used for encryption and hashing, and set your site URL on your Convex deployment.
SITE_URL should be http://localhost:5173 for React (Vite) apps. Update it to your production URL before deploying.Create a Better Auth instance
Create the Better Auth instance in
convex/auth.ts. This example uses the React/Vite setup with the crossDomain plugin, which is required for client-side SPA frameworks.convex/auth.ts
Full-stack frameworks like Next.js do not need the
crossDomain plugin. See the Next.js guide for the server-side variant.Register HTTP routes
Mount the Better Auth route handlers on your Convex HTTP router. This exposes the
/api/auth/* endpoints from your Convex deployment’s .convex.site URL.convex/http.ts
Create an auth client
Create a Better Auth client instance for your frontend. This is used to call sign-in, sign-up, and session management methods from your UI code.
src/lib/auth-client.ts
Next steps
The steps above are the common foundation. Each framework has additional configuration — environment variable names, provider setup, and SSR utilities differ. Follow your framework guide to complete the setup:React (Vite SPA)
Full install guide for React SPAs with Vite
Next.js
Full install guide with SSR, server components, and route handlers
TanStack Start
Full install guide for TanStack Start
SvelteKit
Full install guide for SvelteKit
Expo (React Native)
Full install guide for Expo