PluginBench
Skill
Pass
Audit score 90

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
Prerequisites
  • Nuxt 4+
  • @onmax/nuxt-better-auth package installed
  • Better Auth configured with database (NuxtHub or external)
  • Environment variables for auth configuration
Claude Code
Cursor
Windsurf
Cline

How to use nuxt-better-auth

  1. 1.Install the module via npx skills add
  2. 2.Configure environment variables and auth settings in nuxt.config.ts
  3. 3.Use useUserSession() composable in client components for login/signup flows
  4. 4.Apply route protection via routeRules or definePageMeta in pages
  5. 5.Use requireUserSession() in server routes to protect API endpoints
  6. 6.Optionally integrate Better Auth plugins for admin, passkey, or 2FA features

Use cases

Good for
  • 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
Who it's for
  • 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

Is nuxt-better-auth production-ready?

No, it is currently in alpha (v0.0.2-alpha.19) and APIs may change. Not recommended for production use.

Can I use an external auth backend instead of NuxtHub?

Yes, use clientOnly mode to connect to an external Better Auth backend with CORS configuration.

How do I protect routes based on user roles?

Use routeRules in nuxt.config.ts with auth: { user: { role: 'admin' } } or requireUserSession() in server routes with role checks.

What Better Auth plugins are supported?

The module supports Better Auth plugins including admin panels, passkeys, and two-factor authentication (2FA).

Do I need NuxtHub for the database?

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

FileTopics
references/installation.mdModule setup, env vars, config files
references/client-auth.mduseUserSession, signIn/signUp/signOut, BetterAuthState, safe redirects
references/server-auth.mdserverAuth, getUserSession, requireUserSession
references/route-protection.mdrouteRules, definePageMeta, middleware
references/plugins.mdBetter Auth plugins (admin, passkey, 2FA)
references/database.mdNuxtHub integration, Drizzle schema, custom tables with FKs
references/client-only.mdExternal auth backend, clientOnly mode, CORS
references/types.mdAuthUser, AuthSession, type augmentation

Loading Files

Consider loading these reference files based on your task:

DO NOT load all files at once. Load only what's relevant to your current task.

Key Concepts

ConceptDescription
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