Introduction
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.
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
export default defineNuxtConfig({
hub: { db: 'sqlite' },
})
NUXT_BETTER_AUTH_SECRET="generate-a-32-char-secret"
Create Config Files
import { defineServerAuth } from '@onmax/nuxt-better-auth/config'
export default defineServerAuth({
emailAndPassword: { enabled: true },
})
import { defineClientAuth } from '@onmax/nuxt-better-auth/config'
export default defineClientAuth({})
Run
pnpm dev
npm run dev
You now have API routes at /api/auth/*, a reactive useUserSession() composable, and route protection via definePageMeta.
Recommended Path for Beginners
If this is your first setup, follow this order: