Getting Started
Introduction
Nuxt Better Auth integrates Better Auth with Nuxt for route protection, session management, and schema generation.
Use this page when you want the fastest path to a working Nuxt setup.
This quickstart assumes:
- you want the default full-mode setup
- you are using
pnpm - you want a local login flow working before you customize providers or plugins
If you already know you need a different architecture, jump to NuxtHub, custom database, or external auth backend.
What you will end up with
After this guide you should have:
server/auth.config.tsandapp/auth.config.ts- Better Auth handlers mounted at
/api/auth/* - a valid auth secret:
NUXT_APP_SECRETon Nuxt 4.6+, orNUXT_BETTER_AUTH_SECRET - a reactive
useUserSession()composable in your app
Before you begin
- a local
.envfile - a development server you can start with
pnpm dev
Quickstart
Install the module
npx nuxi module add @nuxtjs/better-auth
Add your secret
Create or update .env:
.env
# Nuxt 4.6 and newer
NUXT_APP_SECRET="replace-with-a-random-32-character-secret"
# Nuxt 4.5 and older
# NUXT_BETTER_AUTH_SECRET="replace-with-a-random-32-character-secret"
Use a high-entropy value. On Nuxt 4.6+, the module derives its auth secret from Nuxt's appSecret when no auth secret is configured. NUXT_BETTER_AUTH_SECRET, BETTER_AUTH_SECRET, and Better Auth's versioned BETTER_AUTH_SECRETS/secrets configuration override it, and one of them is required on older Nuxt versions.
Create the server config
server/auth.config.ts
import { defineServerAuth } from '@nuxtjs/better-auth/config'
export default defineServerAuth({
emailAndPassword: {
enabled: true,
},
})
Create the client config
app/auth.config.ts
import { defineClientAuth } from '@nuxtjs/better-auth/config'
export default defineClientAuth({})
Start Nuxt
pnpm dev
Verify the result
Check these success signals:
- your app starts without auth-related module errors
/api/auth/*routes are registereduseUserSession()is available in a page or component- the generated config files match your project structure
If you use a custom srcDir, the client config lives there instead of app/.
Next steps
- Follow installation for the complete setup checklist.
- Read configuration before adding providers or plugins.
- Set up client usage in your pages and forms.
- Add route protection once the login flow works.