@nuxtjs/better-auth
@nuxtjs/better-auth
Nuxt module for Better Auth with Nuxt-native route protection, SSR-safe session access, auto-imported helpers, and optional NuxtHub-backed schema generation.
Who this is for
Use this module if you want Better Auth in a Nuxt app and you want the Nuxt-specific pieces handled for you:
useUserSession()for reactive auth staterequireUserSession(event)and related server helpers- route protection through
routeRulesanddefinePageMeta({ auth }) - generated
server/auth.config.tsandapp/auth.config.ts - optional NuxtHub database integration and schema generation
Requirements
- Nuxt 4.0 or newer
- Node.js
^22.19.0,^24.11.0, or>=26.0.0 - A Better Auth 1.x version that satisfies this package's peer dependency range
- NuxtHub 0.10.5 or newer when using the optional NuxtHub integration
Install the module
For the fastest path in a Nuxt app:
npx nuxi module add @nuxtjs/better-auth
Then create or confirm these files:
server/auth.config.tsapp/auth.config.ts.envwithNUXT_BETTER_AUTH_SECRET
For the full setup flow, follow the installation guide.
Choose your setup path
- Use NuxtHub integration if you want the shortest path to database-backed auth.
- Use custom database setup if you already have your own database stack.
- Use external auth backend if Better Auth runs in a separate service.
- Use database-less mode for stateless or OAuth-first setups with clear tradeoffs.
Documentation
The documentation site is at better-auth.nuxt.dev.
Recommended reading order:
Development
pnpm install
pnpm dev:docs
Useful commands:
pnpm devto run the playgroundpnpm dev:docsto run the docs sitepnpm lintto lint the repopnpm typecheckto check module typespnpm prepackto build the publishable packagepnpm testto run the test suiteBETTER_AUTH_SECRET=ci-test-secret-12345678901234567890 pnpm dev:buildto build the playground with a test secret for local verification onlypnpm build:docsto build the docs site
See CONTRIBUTING.md for the complete local CI sequence and pull request guidelines.
License
Related Packages
@nuxtjs/sitemap
Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
10,334,110
441
Version History
| Version | Released | License |
|---|---|---|
| 0.3.12 | MIT | |
| 0.3.11 | MIT | |
| 0.3.10 | MIT | |
| 0.3.9 | MIT | |
| 0.3.8 | MIT | |
| 0.3.7 | MIT | |
| 0.3.6 | MIT | |
| 0.3.5 | MIT | |
| 0.3.4 | MIT | |
| 0.3.3 | MIT | |
| 0.3.2 | MIT | |
| 0.3.1 | MIT | |
| 0.3.0 | MIT | |
| 0.2.5 | MIT | |
| 0.2.4 | MIT | |
| 0.2.3 | MIT | |
| 0.2.2 | MIT | |
| 0.2.1 | MIT | |
| 0.2.0 | MIT | |
| 0.1.4 | MIT | |
| 0.1.3 | MIT | |
| 0.0.0 | Proprietary |