nuxt-better-auth
Install this skill
npx skills add onmax/nuxt-skillsWorks across Claude Code, Cursor, Codex, Copilot & Antigravity
The nuxt-better-auth module integrates Better Auth directly into the Nuxt 4 environment, offering a dedicated layer for managing identity and access control. It provides server-side utilities, client-side composables, and integrated route protection rules that respect Nuxt's server architecture. The module handles session lifecycle, database interactions via NuxtHub or Drizzle, and authentication flows including email/password and social providers. It abstracts the complexity of manual session verification by injecting helper functions into both the Nitro server engine and Vue components. Currently in alpha development, this package serves as a bridge for developers who need to implement structured authentication in a modern Nuxt application without writing standard boilerplate for session management or database persistence from scratch. It maintains consistency by syncing client state with server-side authentication events.
When to Use This Skill
- •Building protected admin panels that require specific user roles
- •Implementing standard user registration and login forms with social providers
- •Creating guest-only pages like registration or login portals
- •Restricting API endpoint access to authenticated users only
How to Invoke This Skill
Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:
- “How do I protect my admin dashboard routes in Nuxt?
- “Show me how to implement login with nuxt-better-auth
- “How to use requireUserSession in a server route?
- “Setting up Better Auth with NuxtHub database
- “How to restrict pages to guest users only in Nuxt?
Pro Tips
- 💡Given its 'Alpha Status', always review the official `@onmax/nuxt-better-auth` documentation for the latest API changes before deployment to production environments.
- 💡Leverage the `useUserSession` composable for consistent client-side user state management, ensuring your UI reflects authentication changes in real-time.
- 💡When protecting server routes, combine this skill's guidance with Nuxt's server middleware for robust access control, especially for sensitive API endpoints.
What this skill does
- •Native route protection using Nuxt routeRules and page meta
- •Server-side session validation with requireUserSession
- •Type-safe access to user and session objects across the application
- •Plugin support for 2FA, passkeys, and admin dashboards
- •Direct integration with NuxtHub and Drizzle for persistent storage
When not to use it
- ✕Production-critical projects that cannot tolerate alpha-stage API instability
- ✕Projects requiring auth providers not supported by the underlying Better Auth library
- ✕Simple static sites that do not require server-side session persistence
Example workflow
- Configure the module in nuxt.config.ts with database credentials
- Define route protection rules for your dashboard using routeRules
- Implement login and sign-up forms using the useUserSession composable
- Restrict protected API routes using the requireUserSession utility
- Validate user roles in server logic before returning sensitive data
- Handle redirect logic after authentication success using the onSuccess callback
Prerequisites
- –Nuxt 4
- –Better Auth knowledge
- –NuxtHub or Drizzle configured
Pitfalls & limitations
- !The library is currently in alpha status, meaning APIs are subject to change
- !Incorrect route rule configuration can leave routes accidentally exposed
- !Relying on client-side authentication states without backend verification is insecure
FAQ
How it compares
Unlike manual implementations that require writing custom session middleware and database queries, this module provides a unified declarative API that synchronizes the server, client, and route layers automatically.
📄 Full skill instructions — original source: onmax/nuxt-skills
Authentication module for Nuxt 4+ built on [Better Auth](https://www.better-auth.com/). Provides composables, server utilities, and route protection.
> **Alpha Status**: This module is currently in alpha (v0.0.2-alpha.14) 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
**For Nuxt patterns:** use
nuxt skill**For NuxtHub database:** use
nuxthub skill## Available Guidance
| File | Topics |
| -------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| **[references/installation.md](references/installation.md)** | Module setup, env vars, config files |
| **[references/client-auth.md](references/client-auth.md)** | useUserSession, signIn/signUp/signOut, BetterAuthState, safe redirects |
| **[references/server-auth.md](references/server-auth.md)** | serverAuth, getUserSession, requireUserSession |
| **[references/route-protection.md](references/route-protection.md)** | routeRules, definePageMeta, middleware |
| **[references/plugins.md](references/plugins.md)** | Better Auth plugins (admin, passkey, 2FA) |
| **[references/database.md](references/database.md)** | NuxtHub integration, Drizzle schema, custom tables with FKs |
| **[references/client-only.md](references/client-only.md)** | External auth backend, clientOnly mode, CORS |
| **[references/types.md](references/types.md)** | AuthUser, AuthSession, type augmentation |
## Usage Pattern
**Load based on context:**
- Installing module? → [references/installation.md](references/installation.md)
- Login/signup forms? → [references/client-auth.md](references/client-auth.md)
- API route protection? → [references/server-auth.md](references/server-auth.md)
- Route rules/page meta? → [references/route-protection.md](references/route-protection.md)
- Using plugins? → [references/plugins.md](references/plugins.md)
- Database setup? → [references/database.md](references/database.md)
- External auth backend? → [references/client-only.md](references/client-only.md)
- TypeScript types? → [references/types.md](references/types.md)
**DO NOT read all files at once.** Load based on context.
## 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
- [Module Docs](https://github.com/onmax/nuxt-better-auth)
- [Better Auth Docs](https://www.better-auth.com/)
---
_Token efficiency: Main skill ~300 tokens, each sub-file ~800-1200 tokens_
How to Use This Skill Unit
Option A: Project-Specific (Recommended)
- Click "Download" above
- In your project, create the directory:
.agent/skills/nuxt-better-auth/ - Save the file as
SKILL.md - The agent will automatically discover the skill based on its description.
Option B: Global Installation (All Agents)
Save the file to these locations to make it available across all projects:
- Claude Code:
~/.claude/skills/onmax/nuxt-skills/nuxt-better-auth/SKILL.md - Cursor:
~/.cursor/skills/onmax/nuxt-skills/nuxt-better-auth/SKILL.md - Antigravity:
~/.gemini/antigravity/skills/onmax/nuxt-skills/nuxt-better-auth/SKILL.md
🚀 Install with CLI:npx skills add onmax/nuxt-skills
