Installation and configuration
Happy path
npx nuxi module add @nuxtjs/better-authRequired files:
server/auth.config.tsapp/auth.config.tsor the equivalent file inside yoursrcDir.envwithNUXT_BETTER_AUTH_SECRET
Environment variables
NUXT_BETTER_AUTH_SECRET=replace-with-a-random-32-character-secretSet the public site URL when the deployment platform cannot detect it:
NUXT_PUBLIC_SITE_URL=https://your-domain.comBETTER_AUTH_SECRET is still accepted as a fallback. Prefer NUXT_BETTER_AUTH_SECRET.
For non-destructive secret rotation, keep the current and previous secrets in Better Auth's versioned variable:
BETTER_AUTH_SECRETS=2:current-secret-must-be-at-least-32-characters,1:previous-secret-must-be-at-least-32-charactersMinimal module setup
export default defineNuxtConfig({
modules: ['@nuxtjs/better-auth'],
})Minimal server config
import { defineServerAuth } from '@nuxtjs/better-auth/config'
export default defineServerAuth({
emailAndPassword: {
enabled: true,
},
})Minimal client config
import { defineClientAuth } from '@nuxtjs/better-auth/config'
export default defineClientAuth({})Module-owned values
- Do not set
secretmanually indefineServerAuth(). The module injects it. - Do not set
baseURLmanually in full mode. The module resolves it. - Use
auth.clientOnly = trueonly when Better Auth runs on an external backend. - For database-backed auth with the shortest setup, prefer NuxtHub.
NuxtHub setup
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@nuxtjs/better-auth'],
hub: { db: 'sqlite' },
})See references/database.md for schema setup.
Client-only mode
For external auth backends:
export default defineNuxtConfig({
modules: ['@nuxtjs/better-auth'],
auth: {
clientOnly: true,
},
})See references/client-only.md for full setup.