Skip to main content

Better Auth Setup

Configure Better Auth in Convex and connect it to Nuxt through the same-origin auth proxy.

The maintained topology is:

Browser or Nuxt SSR
  → same-origin /api/auth/*
  → Better Convex Nuxt Nitro proxy
  → Convex HTTP Actions site
  → Better Auth Convex component

This keeps the session cookie on the Nuxt application origin while Better Auth data remains in Convex.

Required files

FileResponsibility
convex/convex.config.tsRegister the Better Auth component
convex/auth.config.tsConfigure Convex JWT verification
convex/auth.tsCreate the component client and Better Auth factory
convex/http.tsRegister Better Auth HTTP routes lazily
nuxt.config.tsRegister the Nuxt module and public Convex URLs

The complete minimal versions are in Add authentication. Keep them as the baseline and add product-specific Better Auth options in createAuth.

Environment ownership

Set these in the Convex environment:

VariablePurpose
SITE_URLExact Nuxt origin used by Better Auth and trusted origins
BETTER_AUTH_SECRETRandom Better Auth signing secret, at least 32 characters

Set these for the Nuxt build/runtime:

VariablePurpose
NUXT_PUBLIC_CONVEX_URLConvex deployment URL ending in .convex.cloud
NUXT_PUBLIC_CONVEX_SITE_URLConvex HTTP Actions URL; required for local/custom domains

SITE_URL must be an exact origin. Use HTTPS outside loopback development. Do not include a path, query, or fragment.

Proxy behavior

The module owns the fixed /api/auth/* path and same-origin credentials behavior. It sends one request to the configured Convex site origin and does not follow server-side redirects.

OAuth and login redirects are returned to the browser. Auth-enabled applications require a Nitro-capable deployment; a purely static host cannot provide the proxy.

The default request and upstream response body limit is 1 MiB. Change limits only for a measured need:

ts
convex: {
  auth: {
    proxy: {
      maxRequestBodyBytes: 1_048_576,
      maxResponseBodyBytes: 1_048_576,
    }
  }
}

Production checklist

  • Use an exact HTTPS SITE_URL.
  • Generate a unique production secret.
  • Configure OAuth callback and trusted origins for the public application origin.
  • Set the correct Convex HTTP Actions URL.
  • Keep Nuxt auth routes uncached.
  • Test sign-up, sign-in, reload, refresh, and sign-out in the deployed topology.
  • Verify protected Convex functions reject anonymous calls directly.