Loading...
Loading...
Step-by-step guide for setting up Better Auth authentication with Convex and TanStack Start. This skill should be used when configuring authentication in a Convex + TanStack Start project, troubleshooting auth issues, or implementing sign up/sign in/sign out flows. Covers installation, environment variables, SSR authentication, route handlers, and the expectAuth pattern.
npx skill4agent add sstobo/convex-skills betterauth-tanstack-convexexpectAuth: truenpm install convex@latest @convex-dev/better-auth
npm install better-auth@1.4.9 --save-exact
npm install @types/node --save-devnpx convex env set BETTER_AUTH_SECRET=$(openssl rand -base64 32)
npx convex env set SITE_URL http://localhost:3000CONVEX_DEPLOYMENT=dev:adjective-animal-123
VITE_CONVEX_URL=https://adjective-animal-123.convex.cloud
VITE_CONVEX_SITE_URL=https://adjective-animal-123.convex.site
VITE_SITE_URL=http://localhost:3000| File | Purpose |
|---|---|
| Register Better Auth component |
| Configure auth provider |
| Create Better Auth instance + |
| Register auth HTTP routes |
| Client-side auth utilities |
| Server-side auth utilities |
| Proxy auth requests to Convex |
| Auth provider wrapper + SSR token |
// Client-side
import { authClient } from '~/lib/auth-client'
// Server-side
import { getToken, fetchAuthQuery, fetchAuthMutation } from '~/lib/auth-server'
// Backend
import { authComponent, createAuth } from './auth'const user = await authComponent.getAuthUser(ctx)
if (!user) throw new Error("Not authenticated")expectAuth: trueawait authClient.signOut({
fetchOptions: {
onSuccess: () => location.reload(),
},
})vite.config.tsssr: {
noExternal: ['@convex-dev/better-auth'],
}const convexQueryClient = new ConvexQueryClient(convexUrl, {
expectAuth: true,
})ConvexBetterAuthProviderQueryClientProviderRootDocument<Outlet />| File | Use When |
|---|---|
| Full step-by-step installation and configuration |