Back to Nuxt.js

nuxt-better-auth

Nuxt.jsAuthenticationSecurityVue.jsBetter AuthWeb DevelopmentAI Agent SkillsFrontend Security
682🕒 2026-06-01Source ↗

Install this skill

npx skills add onmax/nuxt-skills

Works 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

  1. Configure the module in nuxt.config.ts with database credentials
  2. Define route protection rules for your dashboard using routeRules
  3. Implement login and sign-up forms using the useUserSession composable
  4. Restrict protected API routes using the requireUserSession utility
  5. Validate user roles in server logic before returning sensitive data
  6. 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

Is this library ready for production?
No, it is currently in alpha and APIs may change. It is recommended for testing and prototyping.
How does this differ from standard Nuxt Auth modules?
This module is specifically built on top of the Better Auth ecosystem, focusing on tight integration with modern Nuxt 4 server features.
Can I use this with an external auth backend?
Yes, you can use clientOnly mode for external providers, though features like server-side session management may function differently.
How do I secure a server route?
Use the requireUserSession helper function, which checks for a valid session and throws a 401 if authentication fails.

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.

Source & trust

682 stars🕒 Updated 2026-06-01
📄 Full skill instructions — original source: onmax/nuxt-skills
# Nuxt Better Auth

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)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/nuxt-better-auth/
  3. Save the file as SKILL.md
  4. 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

Read the Master Guide: Mastering Agent Skills

Related Skill Units

Recommended Rules

View more rules

Recommended Workflows

View more workflows

Recommended MCP Servers

View more MCP servers

Take It Further

Maximize your productivity with these powerful resources

📋

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
📖

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid nuxt.js issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under Nuxt.js and is published by Onmax, maintained in onmax/nuxt-skills.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.