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

npx nuxi module add @onmax/nuxt-better-auth@alpha

Set Environment Variables

Nuxt 3.19+: Running nuxt prepare or nuxt dev auto-generates the .env file with a secure BETTER_AUTH_SECRET.

Add these environment variables to .env:

  1. Secret Key

The secret encrypts and hashes sensitive data. Must be at least 32 characters with high entropy.

.env
BETTER_AUTH_SECRET=

Or generate via terminal:

openssl rand -base64 32
Prefix the variable with NUXT_ to use Nuxt's runtime config system (recommended for multi-environment deployments): NUXT_BETTER_AUTH_SECRET=
  1. Base URL (Optional)

The module auto-detects the URL on Vercel, Cloudflare Pages, and Netlify. Set manually for other platforms.

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

Create Configuration Files

Nuxt 3.19+: Running nuxt prepare or nuxt dev auto-generates these files. The client config is placed in your srcDir (e.g., app/ or project root).

The module requires two configuration files:

  1. Server Configuration: server/auth.config.ts
  2. Client Configuration: <srcDir>/auth.config.ts (e.g., app/auth.config.ts)

Create these files with the following content:

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

export default defineServerAuth({
  emailAndPassword: { enabled: true }
})
app/auth.config.ts
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'

export default defineClientAuth({})
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.