diff --git a/playground-local/nuxt.config.ts b/playground-local/nuxt.config.ts index 141c816d..63d7ccce 100644 --- a/playground-local/nuxt.config.ts +++ b/playground-local/nuxt.config.ts @@ -15,7 +15,7 @@ export default defineNuxtConfig({ token: { signInResponseTokenPointer: '/token/accessToken' }, - sessionDataType: { id: 'string', email: 'string', name: 'string', role: 'admin | guest | account', subscriptions: "{ id: number, status: 'ACTIVE' | 'INACTIVE' }[]" } + sessionDataType: { id: 'string', email: 'string', name: 'string', role: "'admin' | 'guest' | 'account'", subscriptions: "{ id: number, status: 'ACTIVE' | 'INACTIVE' }[]" } }, session: { // Whether to refresh the session every time the browser window is refocused. diff --git a/src/module.ts b/src/module.ts index 722743fa..47b14714 100644 --- a/src/module.ts +++ b/src/module.ts @@ -188,32 +188,30 @@ export default defineNuxtModule({ filename: 'types/auth.d.ts', getContents: () => [ + '// AUTO-GENERATED BY @sidebase/nuxt-auth', "declare module '#auth' {", - ` const getServerSession: typeof import('${resolve( - './runtime/server/services' - )}').getServerSession`, - ` const getToken: typeof import('${resolve( - './runtime/server/services' - )}').getToken`, - ` const NuxtAuthHandler: typeof import('${resolve( - './runtime/server/services' - )}').NuxtAuthHandler`, - options.provider.type === 'local' - ? genInterface( - 'SessionData', - (options.provider as any).sessionDataType - ) - : '', + ` import RuntimeServerServices from '${resolve('./runtime/server/services')}'`, + ' const getServerSession: RuntimeServerServices.getServerSession', + ' const getToken: RuntimeServerServices.getToken', + ' const NuxtAuthHandler: RuntimeServerServices.NuxtAuthHandler', + ...(options.provider.type === 'local' + ? [genInterface( + 'SessionData', + (options.provider as any).sessionDataType + )] + : [] + ), '}', "declare module 'nitropack' {", + ` import { RouteOptions } from '${resolve('./runtime/types.ts')}'`, ' interface NitroRouteRules {', - ` auth?: import('${resolve('./runtime/types.ts')}').RouteOptions`, + ' auth?: RouteOptions', ' }', ' interface NitroRouteConfig {', - ` auth?: import('${resolve('./runtime/types.ts')}').RouteOptions`, + ' auth?: RouteOptions', ' }', '}', - 'export {}' + '' ].join('\n') }) diff --git a/src/runtime/types.ts b/src/runtime/types.ts index 3b9d27f8..ed08bddc 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -173,7 +173,7 @@ export type ProviderLocal = { * * @default { id: 'string | number' } * @example { id: 'string', name: 'string', email: 'string' } - * @advanced_array_example { id: 'string', email: 'string', name: 'string', role: 'admin | guest | account', subscriptions: "{ id: number, status: 'ACTIVE' | 'INACTIVE' }[]" } + * @advanced_array_example { id: 'string', email: 'string', name: 'string', role: "'admin' | 'guest' | 'account", subscriptions: "{ id: number, status: 'ACTIVE' | 'INACTIVE' }[]" } */ sessionDataType?: SessionDataObject; };