@@ -4,10 +4,14 @@ interface RegisterServerTypeTemplatesInput {
44 serverConfigPath : string
55 hasHubDb : boolean
66 runtimeTypesPath : string
7+ sharedServerConfigSafe : boolean
78}
89
910export function registerServerTypeTemplates ( input : RegisterServerTypeTemplatesInput ) : void {
10- const { serverConfigPath, hasHubDb, runtimeTypesPath } = input
11+ const { serverConfigPath, hasHubDb, runtimeTypesPath, sharedServerConfigSafe } = input
12+ const serverConfigTypeTemplateOptions = sharedServerConfigSafe
13+ ? { nuxt : true , nitro : true , node : true , shared : true }
14+ : { nuxt : true , nitro : true , node : true }
1115
1216 addTypeTemplate ( {
1317 filename : 'types/auth-secondary-storage.d.ts' ,
@@ -53,12 +57,40 @@ declare module '#auth/schema' {
5357` ,
5458 } , { nitro : true } )
5559
60+ addTypeTemplate ( {
61+ filename : 'types/nuxt-better-auth-server-context.d.ts' ,
62+ getContents : ( ) => `
63+ /// <reference path="./nitro-imports.d.ts" />
64+ /// <reference path="./auth-database.d.ts" />
65+ /// <reference path="./auth-schema.d.ts" />
66+ /// <reference path="./auth-secondary-storage.d.ts" />
67+ ${ hasHubDb ? '/// <reference path="../hub/db.d.ts" />' : '' }
68+
69+ export {}
70+ ` ,
71+ } , { node : true } )
72+
73+ addTypeTemplate ( {
74+ filename : 'types/nuxt-better-auth-config-context.d.ts' ,
75+ getContents : ( ) => `
76+ import type { RuntimeConfig } from 'nuxt/schema'
77+
78+ declare module '@onmax/nuxt-better-auth/config' {
79+ interface ServerAuthContextExtension {
80+ runtimeConfig: RuntimeConfig
81+ db: ${ hasHubDb ? `typeof import('@nuxthub/db')['db']` : 'undefined' }
82+ requestOrigin?: string
83+ }
84+ }
85+
86+ ` ,
87+ } , { nuxt : true , nitro : true , node : true , shared : true } )
88+
5689 addTypeTemplate ( {
5790 filename : 'types/nuxt-better-auth-infer.d.ts' ,
5891 getContents : ( ) => `
5992import type { BetterAuthOptions, BetterAuthPlugin, InferPluginTypes, UnionToIntersection } from 'better-auth'
6093import type { InferFieldsOutput } from 'better-auth/db'
61- import type { RuntimeConfig } from 'nuxt/schema'
6294import type createServerAuth from '${ serverConfigPath } '
6395
6496type _RawConfig = ReturnType<typeof createServerAuth>
@@ -88,30 +120,10 @@ type _SessionFallback = _InferModelFieldsFromPlugins<_RawPlugins, 'session'> & _
88120declare module '#nuxt-better-auth' {
89121 interface AuthUser extends _UserFallback {}
90122 interface AuthSession extends _SessionFallback {}
91- interface ServerAuthContext {
92- runtimeConfig: RuntimeConfig
93- db: ${ hasHubDb ? `typeof import('@nuxthub/db')['db']` : 'undefined' }
94- requestOrigin?: string
95- }
96123 type PluginTypes = InferPluginTypes<_Config>
97124}
98-
99- interface _AugmentedServerAuthContext {
100- runtimeConfig: RuntimeConfig
101- db: ${ hasHubDb ? `typeof import('@nuxthub/db')['db']` : 'undefined' }
102- requestOrigin?: string
103- }
104-
105- declare module '@onmax/nuxt-better-auth/config' {
106- import type { BetterAuthOptions, BetterAuthPlugin } from 'better-auth'
107- type ServerAuthConfig = Omit<BetterAuthOptions, 'secret' | 'baseURL'> & {
108- plugins?: readonly BetterAuthPlugin[]
109- }
110- export function defineServerAuth<const R>(config: (ctx: _AugmentedServerAuthContext) => R & ServerAuthConfig): (ctx: _AugmentedServerAuthContext) => R
111- export function defineServerAuth<const R>(config: R & ServerAuthConfig): (ctx: _AugmentedServerAuthContext) => R
112- }
113125` ,
114- } , { nuxt : true , nitro : true , node : true , shared : true } )
126+ } , serverConfigTypeTemplateOptions )
115127
116128 addTypeTemplate ( {
117129 filename : 'types/nuxt-better-auth-social-providers.d.ts' ,
@@ -128,7 +140,7 @@ declare module '#nuxt-better-auth' {
128140 }
129141}
130142` ,
131- } , { nuxt : true , nitro : true , node : true , shared : true } )
143+ } , serverConfigTypeTemplateOptions )
132144
133145 addTypeTemplate ( {
134146 filename : 'types/nuxt-better-auth-nitro.d.ts' ,
@@ -326,7 +338,7 @@ declare module 'nitro/types' {
326338}
327339export {}
328340` ,
329- } , { nuxt : true , nitro : true , node : true } )
341+ } , { nitro : true , node : true } )
330342}
331343
332344interface RegisterSharedTypeTemplatesInput {
0 commit comments