Nuxt Better Auth integrates Nuxt and Better Auth, the TypeScript-first authentication library. You get route protection, session management, and schema generation without configuration. The plugin ecosystem adds features like 2FA, organizations, and passkeys.
This module brings Nuxt-specific enhancements on top of Better Auth:
Auto Configuration
Zero-config setup 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
Building authentication from scratch is hard. Wiring up Better Auth with Nuxt manually involves:
This module does all of that for you. It's designed to be drop-in and zero-config where possible.
Get a working login in 5 minutes with NuxtHub (SQLite).
pnpm add @onmax/nuxt-better-auth better-auth @nuxthub/core
npm install @onmax/nuxt-better-auth better-auth @nuxthub/core
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@onmax/nuxt-better-auth'],
hub: { db: 'sqlite' },
})
NUXT_BETTER_AUTH_SECRET="generate-a-32-char-secret"
import { defineServerAuth } from '@onmax/nuxt-better-auth'
export default defineServerAuth(() => ({
emailAndPassword: { enabled: true },
}))
import { createAuthClient } from 'better-auth/vue'
export function createAppAuthClient(baseURL: string) {
return createAuthClient({ baseURL })
}
pnpm dev
npm run dev
You now have API routes at /api/auth/*, a reactive useUserSession() composable, and route protection via definePageMeta.