You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/1.getting-started/0.index.md
+46-65Lines changed: 46 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,112 +4,93 @@ description: Nuxt Better Auth integrates Better Auth with Nuxt for route protect
4
4
navigation.icon: i-lucide-sparkles
5
5
---
6
6
7
-
Nuxt Better Auth integrates **Nuxt** and **Better Auth**, the TypeScript-first authentication library. You get route protection, session management, and schema generation with minimal setup. The plugin ecosystem adds features like 2FA, organizations, and passkeys.
7
+
Use this page when you want the fastest path to a working Nuxt 4 setup.
**Live Demo** – Try the authentication flow in action.
11
-
::
9
+
This quickstart assumes:
12
10
13
-
## Features
11
+
- you want the default full-mode setup
12
+
- you are using `pnpm`
13
+
- you want a local login flow working before you customize providers or plugins
14
14
15
-
This module brings Nuxt-specific enhancements on top of Better Auth:
15
+
If you already know you need a different architecture, jump to [NuxtHub](/integrations/nuxthub), [custom database](/guides/custom-database), or [external auth backend](/guides/external-auth-backend).
16
16
17
-
::docs-features
18
-
---
19
-
features:
20
-
- title: Auto Configuration
21
-
description: Auto-wires API routes, middleware, and schema with sensible defaults
22
-
- title: Route Protection
23
-
description: Declarative page and API route guards
24
-
- title: Schema Generation
25
-
description: Auto-generate Drizzle schemas
26
-
- title: Reactive Sessions
27
-
description: "`useUserSession()` with SSR support"
28
-
- title: Database Flexibility
29
-
description: Works standalone or with NuxtHub
30
-
- title: Type Safety
31
-
description: Full TypeScript inference
32
-
- title: Auto Imports
33
-
description: Composables and utils ready to use
34
-
- title: Server Utilities
35
-
description: Auth helpers for your API routes
36
-
- title: Powered by Better Auth
37
-
description: 2FA, OAuth, SSO, organizations, and more
38
-
href: https://www.better-auth.com
39
-
---
40
-
::
17
+
## What you will end up with
41
18
42
-
## Why Nuxt Better Auth?
19
+
After this guide you should have:
43
20
44
-
Building authentication from scratch is hard. Wiring up Better Auth with Nuxt manually involves:
45
-
- Setting up API handlers
46
-
- Syncing client/server state
47
-
- Handling redirects
48
-
- Managing database schemas (if using a database)
21
+
-`server/auth.config.ts` and `app/auth.config.ts`
22
+
- Better Auth handlers mounted at `/api/auth/*`
23
+
- a valid `NUXT_BETTER_AUTH_SECRET`
24
+
- a reactive `useUserSession()` composable in your app
49
25
50
-
This module does all of that for you. Just configure your auth providers and the module handles the rest.
26
+
## Before you begin
51
27
52
-
## Quick Start
28
+
- Nuxt `4.x`
29
+
- a local `.env` file
30
+
- a development server you can start with `pnpm dev`
53
31
54
-
Get a working login in 5 minutes with NuxtHub (SQLite).
When you install the module with `nuxi module add`, it prompts you to generate `NUXT_BETTER_AUTH_SECRET` and can append it to your `.env`. `BETTER_AUTH_SECRET` still works as a compatibility fallback. In CI/test environments it auto-generates the secret.
@@ -73,7 +74,7 @@ The module auto-detects the URL on Vercel, Cloudflare Pages, and Netlify. Set ma
73
74
NUXT_PUBLIC_SITE_URL=https://your-domain.com
74
75
```
75
76
76
-
### Create Configuration Files
77
+
### Create configuration files
77
78
78
79
::tip{icon="i-lucide-sparkles"}
79
80
During module install, `server/auth.config.ts` and `<srcDir>/auth.config.ts` are scaffolded if missing. The client config is placed in your `srcDir` (e.g., `app/` or project root).
Use this page when the module is installed and you want to control runtime behavior in `nuxt.config.ts`, `server/auth.config.ts`, and `app/auth.config.ts`.
24
+
26
25
## Module Configuration
27
26
28
27
```ts [nuxt.config.ts]
@@ -278,6 +277,21 @@ Use `NUXT_BETTER_AUTH_SECRET` as the primary secret variable. `BETTER_AUTH_SECRE
278
277
279
278
## For Module Authors
280
279
280
+
## Recommended order
281
+
282
+
1. Configure the module in `nuxt.config.ts`.
283
+
2. Configure Better Auth behavior in `server/auth.config.ts`.
284
+
3. Configure client plugins in `app/auth.config.ts`.
285
+
4. Add route protection with `routeRules` or `definePageMeta({ auth })`.
286
+
287
+
## Verify the result
288
+
289
+
After configuration changes:
290
+
291
+
- restart the Nuxt dev server if you changed schema- or plugin-related settings
292
+
- confirm your app boots without missing-config errors
293
+
- confirm route protection works on at least one protected page and one protected API route
294
+
281
295
Other Nuxt modules can extend the authentication configuration:
0 commit comments