Skip to content

Commit 0ebb0ba

Browse files
authored
docs: clarify type augmentation placement (#171)
1 parent 0a3f757 commit 0ebb0ba

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

docs/content/1.getting-started/4.type-augmentation.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ if (user.value?.role === 'admin') {
4444

4545
Manually extend types when automatic inference doesn't work:
4646

47-
Create a file `types/auth.d.ts`:
47+
Create a file next to `nuxt.config.ts`, for example `nuxt-better-auth.d.ts` (or `nuxt.d.ts`):
4848

49-
```ts [types/auth.d.ts]
49+
```ts [nuxt-better-auth.d.ts]
5050
import '#nuxt-better-auth'
5151

5252
declare module '#nuxt-better-auth' {
@@ -60,12 +60,21 @@ declare module '#nuxt-better-auth' {
6060
The `#nuxt-better-auth` virtual module exports `AuthUser` and `AuthSession` interfaces that reflect your current configuration.
6161
::
6262

63+
::tip
64+
If you prefer putting declaration files under `types/`, make sure they are included by TypeScript in your project:
65+
- Add them to `tsconfig.json` `include`, or
66+
- Reference them from a root `nuxt.d.ts` file (e.g. `/// <reference path="./types/auth.d.ts" />`).
67+
68+
Otherwise, Nuxt/TypeScript may not pick them up and your augmentation will have no effect.
69+
::
70+
6371
## Troubleshooting
6472

6573
**Types not updating?**
6674
1. Restart your IDE's TypeScript server
6775
2. Run `npx nuxi prepare` to regenerate types
6876
3. Check that your `server/auth.config.ts` has no syntax errors
77+
4. Ensure your augmentation `.d.ts` file is included by TypeScript (see note above)
6978

7079
::callout{icon="i-lucide-arrow-right" to="/getting-started/how-it-works"}
7180
Now that you are set up, learn **How it Works**.

docs/content/2.core-concepts/3.route-protection.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export default defineNuxtConfig({
5858

5959
If `redirectTo` is omitted, shorthand defaults apply (`'user' -> '/login'`, `'guest' -> '/'`).
6060

61+
::tip
62+
If `auth: { user: { ... } }` complains about missing fields (e.g. `role`), ensure your Better Auth plugin fields are inferred or that you have a working `#nuxt-better-auth` type augmentation in a root `*.d.ts` file.
63+
:read-more{to="/getting-started/type-augmentation" title="Type Augmentation"}
64+
::
65+
6166
::note
6267
These rules are automatically synced to the client-side router, ensuring instant redirects without server roundtrips for navigation.
6368
::

0 commit comments

Comments
 (0)