nuxt-better-auth
onmax/nuxt-skills
Authentication for Nuxt 4+ with Better Auth – composables, server helpers, and route protection.
What is nuxt-better-auth?
Nuxt Better Auth is an authentication module for Nuxt 4+ built on Better Auth. Use it to implement login/signup flows, protect routes, access user sessions server-side, and integrate Better Auth plugins. Currently in alpha and not recommended for production.
- Provides useUserSession() composable for client-side auth state and sign-in/out methods
- Offers server helpers (requireUserSession, serverAuth) for API route protection and session access
- Supports route protection via routeRules and middleware with role-based access control
- Integrates Better Auth plugins for admin panels, passkeys, and two-factor authentication
- Enables database setup with NuxtHub and Drizzle schema with custom tables
- Supports clientOnly mode for external auth backends with CORS configuration
How to install nuxt-better-auth
npx skills add https://github.com/onmax/nuxt-skills --skill nuxt-better-auth- Nuxt 4+
- @onmax/nuxt-better-auth package installed
- Better Auth configured with database (NuxtHub or external)
- Environment variables for auth configuration
How to use nuxt-better-auth
- 1.Install the module via npx skills add
- 2.Configure environment variables and auth settings in nuxt.config.ts
- 3.Use useUserSession() composable in client components for login/signup flows
- 4.Apply route protection via routeRules or definePageMeta in pages
- 5.Use requireUserSession() in server routes to protect API endpoints
- 6.Optionally integrate Better Auth plugins for admin, passkey, or 2FA features
Use cases
- Building login and signup flows in Nuxt applications with email/password authentication
- Protecting admin routes and API endpoints based on user roles and permissions
- Accessing authenticated user data in server-side API routes and middleware
- Integrating two-factor authentication or passkey support via Better Auth plugins
- Setting up a self-hosted authentication backend with NuxtHub database
- Nuxt 4+ developers building applications with authentication requirements
- Full-stack developers implementing role-based access control
- Teams using Better Auth and wanting Nuxt-specific composables and helpers
- Developers integrating advanced auth features like 2FA or passkeys
nuxt-better-auth FAQ
No, it is currently in alpha (v0.0.2-alpha.19) and APIs may change. Not recommended for production use.
Yes, use clientOnly mode to connect to an external Better Auth backend with CORS configuration.
Use routeRules in nuxt.config.ts with auth: { user: { role: 'admin' } } or requireUserSession() in server routes with role checks.
The module supports Better Auth plugins including admin panels, passkeys, and two-factor authentication (2FA).
NuxtHub is recommended but optional. You can use Drizzle with your own database or an external auth backend in clientOnly mode.
Full instructions (SKILL.md)
Source of truth, from onmax/nuxt-skills.
name: nuxt-better-auth description: Use when implementing auth in Nuxt apps with @onmax/nuxt-better-auth - provides useUserSession composable, server auth helpers, route protection, and Better Auth plugins integration. license: MIT
Nuxt Better Auth
Authentication module for Nuxt 4+ built on Better Auth. Provides composables, server utilities, and route protection.
Alpha Status: This module is currently in alpha (v0.0.2-alpha.19) and not recommended for production use. APIs may change.
When to Use
- Installing/configuring
@onmax/nuxt-better-auth - Implementing login/signup/signout flows
- Protecting routes (client and server)
- Accessing user session in API routes
- Integrating Better Auth plugins (admin, passkey, 2FA)
- Setting up database with NuxtHub
- Using clientOnly mode for external auth backends
- Adding i18n support with
@nuxtjs/i18n
For Nuxt patterns: use nuxt skill
For NuxtHub database: use nuxthub skill
Available Guidance
| File | Topics |
|---|---|
| references/installation.md | Module setup, env vars, config files |
| references/client-auth.md | useUserSession, signIn/signUp/signOut, BetterAuthState, safe redirects |
| references/server-auth.md | serverAuth, getUserSession, requireUserSession |
| references/route-protection.md | routeRules, definePageMeta, middleware |
| references/plugins.md | Better Auth plugins (admin, passkey, 2FA) |
| references/database.md | NuxtHub integration, Drizzle schema, custom tables with FKs |
| references/client-only.md | External auth backend, clientOnly mode, CORS |
| references/types.md | AuthUser, AuthSession, type augmentation |
Loading Files
Consider loading these reference files based on your task:
- references/installation.md - if installing or configuring the module
- references/client-auth.md - if building login/signup/signout flows
- references/server-auth.md - if protecting API routes or accessing user session server-side
- references/route-protection.md - if using routeRules or definePageMeta for auth
- references/plugins.md - if integrating Better Auth plugins (admin, passkey, 2FA)
- references/database.md - if setting up database with NuxtHub or Drizzle
- references/client-only.md - if using external auth backend with clientOnly mode
- references/types.md - if working with AuthUser, AuthSession, or type augmentation
DO NOT load all files at once. Load only what's relevant to your current task.
Key Concepts
| Concept | Description |
|---|---|
useUserSession() | Client composable - user, session, loggedIn, signIn/Out methods |
requireUserSession() | Server helper - throws 401/403 if not authenticated |
auth route mode | 'user', 'guest', { user: {...} }, or false |
serverAuth() | Get Better Auth instance in server routes |
Quick Reference
// Client: useUserSession()
const { user, loggedIn, signIn, signOut } = useUserSession()
await signIn.email({ email, password }, { onSuccess: () => navigateTo('/') })
// Server: requireUserSession()
const { user } = await requireUserSession(event, { user: { role: 'admin' } })
// nuxt.config.ts: Route protection
routeRules: {
'/admin/**': { auth: { user: { role: 'admin' } } },
'/login': { auth: 'guest' },
'/app/**': { auth: 'user' }
}
Resources
Token efficiency: Main skill ~300 tokens, each sub-file ~800-1200 tokens
Related skills
More from onmax/nuxt-skills and the wider catalog.

nuxt-content
Typed content collections, markdown rendering, and CMS features for Nuxt with SQL queries and NuxtStudio integration.

nuxt-modules
Create, test, and publish Nuxt modules with defineNuxtModule patterns, Kit utilities, and CI/CD automation.

nuxt-seo
Nuxt SEO meta-module for robots.txt, sitemaps, OG images, and structured data.

nuxt-studio
Use when working with Nuxt Studio, the self-hosted open-source CMS for Nuxt Content sites - provides visual editing, media management, Git-based publishing, auth providers, and AI content assistance

nuxt-ui
Build styled UI with @nuxt/ui v4 components, forms, tables, modals, and Tailwind Variants theming.

nuxthub
Full-stack Nuxt with Drizzle ORM database, KV storage, blob uploads, and cache—multi-cloud ready.