Skip to content

Commit 508a496

Browse files
committed
feat: auto-generate AppAuthClient type
1 parent d64c0a9 commit 508a496

File tree

7 files changed

+12
-14
lines changed

7 files changed

+12
-14
lines changed

docs/app/components/content/landing/hero.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ tabs:
3737
plugins: [adminClient(), twoFactorClient()],
3838
})
3939
}
40-
41-
export type AppAuthClient = ReturnType<typeof createAppAuthClient>
4240
- name: app/pages/login.vue
4341
code: |
4442
<script setup lang="ts">

docs/content/1.getting-started/4.client-setup.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ export function createAppAuthClient(baseURL: string) {
2020
plugins: []
2121
})
2222
}
23-
24-
// Export type for auto-inference
25-
export type AppAuthClient = ReturnType<typeof createAppAuthClient>
2623
```
2724

2825
::callout{icon="i-lucide-info"}

playground/app/auth.client.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,3 @@ export function createAppAuthClient(baseURL: string) {
88
plugins: [adminClient(), passkeyClient()],
99
})
1010
}
11-
12-
export type AppAuthClient = ReturnType<typeof createAppAuthClient>

src/module.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ declare module '#nuxt-better-auth' {
116116
`,
117117
})
118118

119+
addTypeTemplate({
120+
filename: 'types/nuxt-better-auth-client.d.ts',
121+
getContents: () => `
122+
import type { createAppAuthClient } from '${clientConfigPath}'
123+
declare module '#nuxt-better-auth' {
124+
export type AppAuthClient = ReturnType<typeof createAppAuthClient>
125+
}
126+
`,
127+
})
128+
119129
addTypeTemplate({
120130
filename: 'types/nuxt-better-auth-nitro.d.ts',
121131
getContents: () => `
@@ -129,7 +139,7 @@ declare module 'nitropack/types' {
129139

130140
// HMR
131141
nuxt.hook('builder:watch', async (_event, relativePath) => {
132-
if (relativePath.includes('auth.config')) {
142+
if (relativePath.includes('auth.config') || relativePath.includes('auth.client')) {
133143
await updateTemplates({ filter: t => t.filename.includes('nuxt-better-auth') })
134144
}
135145
})

src/runtime/app/composables/useUserSession.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { AppAuthClient } from '#auth/client'
2-
import type { AuthSession, AuthUser } from '#nuxt-better-auth'
1+
import type { AppAuthClient, AuthSession, AuthUser } from '#nuxt-better-auth'
32
import { createAppAuthClient } from '#auth/client'
43
import { computed, useRequestHeaders, useRuntimeConfig, useState, watch } from '#imports'
54
import { consola } from 'consola'

test/fixtures/basic/app/auth.client.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ import { createAuthClient } from 'better-auth/vue'
33
export function createAppAuthClient(baseURL: string) {
44
return createAuthClient({ baseURL })
55
}
6-
7-
export type AppAuthClient = ReturnType<typeof createAppAuthClient>

test/fixtures/dbless/app/auth.client.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ import { createAuthClient } from 'better-auth/vue'
33
export function createAppAuthClient(baseURL: string) {
44
return createAuthClient({ baseURL })
55
}
6-
7-
export type AppAuthClient = ReturnType<typeof createAppAuthClient>

0 commit comments

Comments
 (0)