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

Introduction

Nuxt Better Auth integrates Better Auth with Nuxt for route protection, session management, and schema generation.

Use this page when you want the fastest path to a working Nuxt 4 setup.

This quickstart assumes:

  • you want the default full-mode setup
  • you are using pnpm
  • you want a local login flow working before you customize providers or plugins

If you already know you need a different architecture, jump to NuxtHub, custom database, or external auth backend.

What you will end up with

After this guide you should have:

  • server/auth.config.ts and app/auth.config.ts
  • Better Auth handlers mounted at /api/auth/*
  • a valid NUXT_BETTER_AUTH_SECRET
  • a reactive useUserSession() composable in your app

Before you begin

  • Nuxt 4.x
  • a local .env file
  • a development server you can start with pnpm dev

Quickstart

Install the module

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

Add your secret

Create or update .env:

.env
NUXT_BETTER_AUTH_SECRET="replace-with-a-random-32-character-secret"

Use a high-entropy value. The module also accepts BETTER_AUTH_SECRET as a fallback, but NUXT_BETTER_AUTH_SECRET is the recommended variable.

Create the server config

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

export default defineServerAuth({
  emailAndPassword: {
    enabled: true,
  },
})

Create the client config

app/auth.config.ts
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'

export default defineClientAuth({})

Start Nuxt

pnpm dev

Verify the result

Check these success signals:

  • your app starts without auth-related module errors
  • /api/auth/* routes are registered
  • useUserSession() is available in a page or component
  • the generated config files match your project structure

If you use a custom srcDir, the client config lives there instead of app/.

Next steps

  1. Follow installation for the complete setup checklist.
  2. Read configuration before adding providers or plugins.
  3. Set up client usage in your pages and forms.
  4. Add route protection once the login flow works.