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.

Nuxt Better Auth integrates Nuxt and Better Auth, the TypeScript-first authentication library. You get route protection, session management, and schema generation with minimal setup. The plugin ecosystem adds features like 2FA, organizations, and passkeys.

Live Demo – Try the authentication flow in action.

Features

This module brings Nuxt-specific enhancements on top of Better Auth:

Auto Configuration

Auto-wires API routes, middleware, and schema with sensible defaults

Route Protection

Declarative page and API route guards

Schema Generation

Auto-generate Drizzle schemas

Reactive Sessions

useUserSession() with SSR support

Database Flexibility

Works standalone or with NuxtHub

Type Safety

Full TypeScript inference

Auto Imports

Composables and utils ready to use

Server Utilities

Auth helpers for your API routes

Powered by Better Auth

2FA, OAuth, SSO, organizations, and more

Why Nuxt Better Auth?

Building authentication from scratch is hard. Wiring up Better Auth with Nuxt manually involves:

  • Setting up API handlers
  • Syncing client/server state
  • Handling redirects
  • Managing database schemas (if using a database)

This module does all of that for you. Just configure your auth providers and the module handles the rest.

Quick Start

Get a working login in 5 minutes with NuxtHub (SQLite).

Install

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

Configure

nuxt.config.ts
export default defineNuxtConfig({
  hub: { db: 'sqlite' },
})
.env
BETTER_AUTH_SECRET="generate-a-32-char-secret"

Create Config Files

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({})

Run

pnpm dev

You now have API routes at /api/auth/*, a reactive useUserSession() composable, and route protection via definePageMeta.

Continue to Installation for detailed setup options.