AGENT SKILL

nuxt-better-auth

Use when implementing auth in Nuxt apps with @onmax/nuxt-better-auth - provides client composables, server helpers, route protection, session refresh helpers, and Better Auth plugin integration.

License 许可
MIT
最近更新
2026-11-15
Stars
★ 0
Forks
0

01 前言 Front Matter

name
nuxt-better-auth
license
MIT
description
Use when implementing auth in Nuxt apps with @onmax/nuxt-better-auth - provides client composables, server helpers, route protection, session refresh helpers, and Better Auth plugin integration.

02 资源文件 11

03 SKILL.md 正文

Nuxt Better Auth

Authentication module for Nuxt 4+ built on Better Auth. It adds Nuxt-specific setup, route protection, server helpers, and typed auth state.

Alpha status: the package is still pre-stable. Verify behavior against the current docs and source before relying on edge cases.

When to Use

  • Installing/configuring @onmax/nuxt-better-auth
  • Implementing sign-in, sign-up, sign-out, or custom auth flows
  • Protecting routes (client and server)
  • Accessing user session in API routes
  • Refreshing session state after custom auth endpoints or server-side session changes
  • Integrating Better Auth plugins (admin, passkey, 2FA)
  • Setting up database with NuxtHub
  • Using clientOnly mode for external auth backends

Available Guidance

File Topics
references/installation.md install flow, env vars, config files
references/client-auth.md useUserSession, client methods, redirects, loading states, custom actions
references/server-auth.md serverAuth, session helpers, refreshSessionCookieCache, API enforcement
references/route-protection.md route rules, page meta, API protection
references/plugins.md plugin pairing between server and client
references/database.md NuxtHub schema generation, secondary storage
references/client-only.md external Better Auth backends and clientOnly mode
references/types.md public auth types and augmentation

Usage Pattern

Do not load every reference file by default. Pick the smallest file that matches the task.

Key Concepts

Concept Description
useUserSession() Client composable - user, session, loggedIn, refresh, sign-out
runWithSessionRefresh() Refresh local session after custom auth endpoints
requireUserSession() Server helper - throws 401/403 if not authenticated
refreshSessionCookieCache() Refresh Better Auth's cached session cookie after server updates
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('/') })
// Client: custom auth endpoint
await runWithSessionRefresh(() => $fetch('/api/custom-login', { method: 'POST', body }))
// Server: requireUserSession()
const { user } = await requireUserSession(event, { user: { role: 'admin' } })
// Server: after updating fields returned by session helpers
await updateCurrentUser(event)
await refreshSessionCookieCache(event)
// nuxt.config.ts: Route protection
routeRules: {
  '/admin/**': { auth: { user: { role: 'admin' } } },
  '/login': { auth: 'guest' },
  '/app/**': { auth: 'user' }
}

Broad rules such as '/**': { auth: 'user' } skip framework/module internals like /_nuxt/**, /_ipx/**, /api/auth/**, /api/_better-auth/**, and /api/_nuxt_icon/**.

Resources

04 同仓库更多 Skills

wolfstar-project
wolfstar-project/wolfstar.rocks

web-perf

Audit, diagnose, or optimize website loading and interaction performance, Core Web Vitals, and Lighthouse performance scores.

★ 0
wolfstar-project
wolfstar-project/wolfstar.rocks

unlighthouse

Run Google Lighthouse on every page of a site with the unlighthouse CLI, and fail CI on low scores with unlighthouse-ci. Use when a task mentions unlighthouse, unlighthouse-ci, site-wide Lighthouse scans, performance budgets in CI, unlighthouse.config.ts, defineUnlighthouseConfig, scanner.exclude, dynamic sampling, the authenticate hook, or a scan that never exits, skips pages, or refuses to clear its output folder.

★ 0
wolfstar-project
wolfstar-project/wolfstar.rocks

performance-optimization

Optimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.

★ 0
wolfstar-project
wolfstar-project/wolfstar.rocks

fixing-accessibility

Audit and fix HTML accessibility issues including ARIA labels, keyboard navigation, focus management, color contrast, and form errors. Use when adding interactive controls, forms, dialogs, or reviewing WCAG compliance.

★ 0
wolfstar-project
wolfstar-project/wolfstar.rocks

better-accessibility

Reviews and fixes keyboard and focus behavior, ARIA, accessible names, forms, screen-reader announcements, motion and zoom in your project against WCAG 2.2.

★ 0
wolfstar-project
wolfstar-project/wolfstar.rocks

web-perf

Audit, diagnose, or optimize website loading and interaction performance, Core Web Vitals, and Lighthouse performance scores.

★ 0