Installation
Install @nuxtjs/better-auth in my Nuxt app.
- Read the raw installation documentation first: https://better-auth.nuxt.dev/raw/getting-started/installation.md
- Run `npx nuxi module add @nuxtjs/better-auth`
- Set `NUXT_BETTER_AUTH_SECRET` or `BETTER_AUTH_SECRETS` in `.env` (at least 32 chars per current secret, high entropy)
- Set `NUXT_PUBLIC_SITE_URL` for Cloudflare Workers, custom domains, and production hosts without a supported platform URL variable
- Create `server/auth.config.ts` using `defineServerAuth` from `@nuxtjs/better-auth/config`
- Create `app/auth.config.ts` using `defineClientAuth` from `@nuxtjs/better-auth/config`
- The module auto-injects `secret` and `baseURL` — do not configure them manually
- In `defineServerAuth`, use the app config callback's `requestOrigin` when Better Auth needs the current request host, such as `trustedOrigins`
Use this page when you want the full install checklist rather than the shorter quickstart.
Prerequisites
- Nuxt 4.0 or newer
- Node.js
^22.19.0,^24.11.0, or>=26.0.0 - A Better Auth 1.x version that satisfies this package's peer dependency range
- NuxtHub 0.10.5 or newer if you plan to use the optional NuxtHub integration
- a package manager configured for your app
- a local
.envfile or deployment environment variable system
Add to project
Install the module
npx nuxi module add @nuxtjs/better-auth
Set environment variables
nuxi module add, it prompts you to generate NUXT_BETTER_AUTH_SECRET and can append it to your .env. The prompt is skipped when NUXT_BETTER_AUTH_SECRET, BETTER_AUTH_SECRET, or BETTER_AUTH_SECRETS is already configured. In CI/test environments it auto-generates the singular secret.Add these environment variables to .env:
- Secret Key
The secret encrypts and hashes sensitive data. Must be at least 32 characters with high entropy.
NUXT_BETTER_AUTH_SECRET=
Or generate via terminal:
openssl rand -base64 32
NUXT_BETTER_AUTH_SECRET for Nuxt runtime config and multi-environment deployments. BETTER_AUTH_SECRET remains supported as a fallback.For non-destructive rotation, use Better Auth's versioned environment variable instead:
BETTER_AUTH_SECRETS=2:current-secret-must-be-at-least-32-characters,1:previous-secret-must-be-at-least-32-characters
- Base URL
Set NUXT_PUBLIC_SITE_URL for Cloudflare Workers, custom domains, and production hosts without a supported platform URL variable. For platform domains, the module can use VERCEL_URL (Vercel), CF_PAGES_URL (Cloudflare Pages), or URL (Netlify) when available at runtime.
NUXT_PUBLIC_SITE_URL=https://your-domain.com
Cloudflare Workers does not supply CF_PAGES_URL. Configure NUXT_PUBLIC_SITE_URL in the Worker's runtime variables, including for workers.dev deployments. Without an explicit or supported platform URL, production auth initialization fails.
Create configuration files
server/auth.config.ts and <srcDir>/auth.config.ts are scaffolded if missing. The client config is placed in your srcDir (e.g., app/ or project root).The module requires two configuration files:
- Server Configuration:
server/auth.config.ts - Client Configuration:
<srcDir>/auth.config.ts(e.g.,app/auth.config.ts)
Create these files with the following content:
import { defineServerAuth } from '@nuxtjs/better-auth/config'
export default defineServerAuth({
emailAndPassword: { enabled: true }
})
import { defineClientAuth } from '@nuxtjs/better-auth/config'
export default defineClientAuth({})
Verify the installation
Confirm all of the following:
- Nuxt starts without missing-config errors
server/auth.config.tsexistsapp/auth.config.tsor yoursrcDirequivalent exists- a singular or versioned auth secret is available at runtime
Next steps
- Continue with configuration to set module options and route protection.
- Continue with client setup to wire sign-in and sign-out flows.
- If you need durable persistence, pick either NuxtHub integration or custom database.