pnpm add @onmax/nuxt-better-auth better-auth
npm install @onmax/nuxt-better-auth better-auth
yarn add @onmax/nuxt-better-auth better-auth
npx nuxi module add @onmax/nuxt-better-auth to auto-inject the module into nuxt.config.ts.auto-install-peers=true to .npmrc or install manually: pnpm add better-authAdd these environment variables to .env:
A secret value used for encryption and hashing. Must be at least 32 characters with high entropy.
NUXT_BETTER_AUTH_SECRET=
Or generate via terminal:
openssl rand -base64 32
Auto-detected on Vercel, Cloudflare Pages, and Netlify. Set manually for other platforms.
NUXT_PUBLIC_SITE_URL=https://your-domain.com
Add the module to your nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@onmax/nuxt-better-auth'],
})
Two configuration files connect Nuxt with Better Auth.
server/auth.config.tsapp/auth.config.tsCreate these two configuration files:
import { defineServerAuth } from '@onmax/nuxt-better-auth'
export default defineServerAuth(() => ({
emailAndPassword: { enabled: true }
}))
import { createAuthClient } from 'better-auth/vue'
export function createAppAuthClient(baseURL: string) {
return createAuthClient({ baseURL })
}