This library is in early development. Expect breaking changes.
Getting Started

Installation

Learn how to add Nuxt Better Auth to your Nuxt project.

Prerequisites

  • Nuxt v3.10+

Add to project

Install the module

pnpm add @onmax/nuxt-better-auth better-auth
You can also run npx nuxi module add @onmax/nuxt-better-auth to auto-inject the module into nuxt.config.ts.
pnpm users: Add auto-install-peers=true to .npmrc or install manually: pnpm add better-auth

Set Environment Variables

Add these environment variables to .env:

  1. Secret Key

A secret value used for encryption and hashing. Must be at least 32 characters with high entropy.

.env
NUXT_BETTER_AUTH_SECRET=

Or generate via terminal:

openssl rand -base64 32
  1. Base URL (Optional)

Auto-detected on Vercel, Cloudflare Pages, and Netlify. Set manually for other platforms.

.env
NUXT_PUBLIC_SITE_URL=https://your-domain.com

Configure Nuxt

Add the module to your nuxt.config.ts:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@onmax/nuxt-better-auth'],
})

Create Configuration Files

Two configuration files connect Nuxt with Better Auth.

  1. Server Configuration: server/auth.config.ts
  2. Client Configuration: app/auth.config.ts

Create these two configuration files:

server/auth.config.ts
import { defineServerAuth } from '@onmax/nuxt-better-auth'

export default defineServerAuth(() => ({
  emailAndPassword: { enabled: true }
}))
app/auth.config.ts
import { createAuthClient } from 'better-auth/vue'

export function createAppAuthClient(baseURL: string) {
  return createAuthClient({ baseURL })
}
Need database persistence? See NuxtHub Integration for auto-generated schemas and full database support.
Bring your own database? Use Drizzle, Prisma, or Kysely adapters with any database.
Continue to Configuration to set up these files.