From fc645e524a5275de9a189153014fcd233f37a6fe Mon Sep 17 00:00:00 2001 From: onmax Date: Thu, 12 Feb 2026 21:17:24 +0100 Subject: [PATCH 1/5] fix(types): preserve #107 auth inference --- playground/app/types/auth.d.ts | 9 ----- src/module.ts | 1 - .../nuxt-better-auth-infer-template.ts | 34 ++++++++++++++++++ src/module/type-templates.ts | 35 +++---------------- src/runtime/config.ts | 14 ++++---- src/runtime/server/utils/auth.ts | 26 ++++---------- src/runtime/types.ts | 1 + src/runtime/types/infer.ts | 31 ++++++++++++++++ test/fixtures/type-infer-107/app/app.vue | 3 ++ .../type-infer-107/app/auth.config.ts | 3 ++ test/fixtures/type-infer-107/nuxt.config.ts | 10 ++++++ .../type-infer-107/server/auth.config.ts | 34 ++++++++++++++++++ test/fixtures/type-infer-107/tsconfig.json | 3 ++ test/type-infer-107.test.ts | 31 ++++++++++++++++ 14 files changed, 169 insertions(+), 66 deletions(-) delete mode 100644 playground/app/types/auth.d.ts create mode 100644 src/module/templates/nuxt-better-auth-infer-template.ts create mode 100644 src/runtime/types/infer.ts create mode 100644 test/fixtures/type-infer-107/app/app.vue create mode 100644 test/fixtures/type-infer-107/app/auth.config.ts create mode 100644 test/fixtures/type-infer-107/nuxt.config.ts create mode 100644 test/fixtures/type-infer-107/server/auth.config.ts create mode 100644 test/fixtures/type-infer-107/tsconfig.json create mode 100644 test/type-infer-107.test.ts diff --git a/playground/app/types/auth.d.ts b/playground/app/types/auth.d.ts deleted file mode 100644 index 7cf40ce..0000000 --- a/playground/app/types/auth.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Augment AuthUser with plugin fields (admin, twoFactor) -declare module '#nuxt-better-auth' { - interface AuthUser { - role?: 'user' | 'admin' - twoFactorEnabled?: boolean - } -} - -export {} diff --git a/src/module.ts b/src/module.ts index 96bc6ab..43b4ece 100644 --- a/src/module.ts +++ b/src/module.ts @@ -164,7 +164,6 @@ export default defineNuxtModule({ nuxt.options.alias['#auth/database'] = databaseTemplate.dst registerServerTypeTemplates({ - serverConfigPath, hasHubDb, runtimeTypesPath: resolver.resolve('./runtime/types'), }) diff --git a/src/module/templates/nuxt-better-auth-infer-template.ts b/src/module/templates/nuxt-better-auth-infer-template.ts new file mode 100644 index 0000000..51be730 --- /dev/null +++ b/src/module/templates/nuxt-better-auth-infer-template.ts @@ -0,0 +1,34 @@ +export const nuxtBetterAuthInferTemplate = ` +import type { BetterAuthOptions } from 'better-auth' +import type { RuntimeConfig } from 'nuxt/schema' +import type { BetterAuthConfigFromServerConfig, InferPluginTypes, SessionFieldsFromConfig, UserFieldsFromConfig } from '__RUNTIME_TYPES_PATH__' +import type createServerAuth from '#auth/server' + +type _RawConfig = ReturnType +type _Config = BetterAuthConfigFromServerConfig<_RawConfig> + +declare module '#nuxt-better-auth' { + interface AuthUser extends UserFieldsFromConfig<_RawConfig> {} + interface AuthSession extends SessionFieldsFromConfig<_RawConfig> {} + interface ServerAuthContext { + runtimeConfig: RuntimeConfig + db: __DB_TYPE__ + } + type PluginTypes = InferPluginTypes<_Config> +} + +interface _AugmentedServerAuthContext { + runtimeConfig: RuntimeConfig + db: __DB_TYPE__ +} + +declare module '@onmax/nuxt-better-auth/config' { + import type { BetterAuthOptions } from 'better-auth' + type ServerAuthConfigBase = Omit + type ServerAuthConfigWithPlugins = ServerAuthConfigBase & { plugins: readonly unknown[] } + export function defineServerAuth(config: R): (ctx: _AugmentedServerAuthContext) => R + export function defineServerAuth(config: (ctx: _AugmentedServerAuthContext) => R): (ctx: _AugmentedServerAuthContext) => R + export function defineServerAuth(config: R): (ctx: _AugmentedServerAuthContext) => R + export function defineServerAuth(config: (ctx: _AugmentedServerAuthContext) => R): (ctx: _AugmentedServerAuthContext) => R +} +` diff --git a/src/module/type-templates.ts b/src/module/type-templates.ts index 8192fd2..71d8f67 100644 --- a/src/module/type-templates.ts +++ b/src/module/type-templates.ts @@ -1,13 +1,13 @@ import { addTypeTemplate } from '@nuxt/kit' +import { nuxtBetterAuthInferTemplate } from './templates/nuxt-better-auth-infer-template' interface RegisterServerTypeTemplatesInput { - serverConfigPath: string hasHubDb: boolean runtimeTypesPath: string } export function registerServerTypeTemplates(input: RegisterServerTypeTemplatesInput): void { - const { serverConfigPath, hasHubDb, runtimeTypesPath } = input + const { hasHubDb, runtimeTypesPath } = input addTypeTemplate({ filename: 'types/auth-secondary-storage.d.ts', @@ -36,34 +36,9 @@ declare module '#auth/database' { addTypeTemplate({ filename: 'types/nuxt-better-auth-infer.d.ts', - getContents: () => ` -import type { InferUser, InferSession, InferPluginTypes } from 'better-auth' -import type { RuntimeConfig } from 'nuxt/schema' -import type createServerAuth from '${serverConfigPath}' - -type _Config = ReturnType - -declare module '#nuxt-better-auth' { - interface AuthUser extends InferUser<_Config> {} - interface AuthSession extends InferSession<_Config> {} - interface ServerAuthContext { - runtimeConfig: RuntimeConfig - ${hasHubDb ? `db: typeof import('@nuxthub/db')['db']` : ''} - } - type PluginTypes = InferPluginTypes<_Config> -} - -interface _AugmentedServerAuthContext { - runtimeConfig: RuntimeConfig - ${hasHubDb ? `db: typeof import('@nuxthub/db')['db']` : 'db: unknown'} -} - -declare module '@onmax/nuxt-better-auth/config' { - import type { BetterAuthOptions } from 'better-auth' - type ServerAuthConfig = Omit - export function defineServerAuth(config: T | ((ctx: _AugmentedServerAuthContext) => T)): (ctx: _AugmentedServerAuthContext) => T -} -`, + getContents: () => nuxtBetterAuthInferTemplate + .replaceAll('__RUNTIME_TYPES_PATH__', runtimeTypesPath) + .replaceAll('__DB_TYPE__', hasHubDb ? `typeof import('@nuxthub/db')['db']` : 'unknown'), }, { nuxt: true, nitro: true, node: true }) addTypeTemplate({ diff --git a/src/runtime/config.ts b/src/runtime/config.ts index 26d6e3e..01d422d 100644 --- a/src/runtime/config.ts +++ b/src/runtime/config.ts @@ -5,20 +5,20 @@ import type { CasingOption } from '../schema-generator' import type { ServerAuthContext } from './types/augment' import { createAuthClient } from 'better-auth/vue' -// Re-export for declaration merging with generated types export type { ServerAuthContext } export interface ClientAuthContext { siteUrl: string } -export type ServerAuthConfig = Omit +export type ServerAuthConfigBase = Omit +export type ServerAuthConfig = ServerAuthConfigBase export type ClientAuthConfig = Omit & { baseURL?: string } +type ServerAuthConfigWithPlugins = ServerAuthConfigBase & { plugins: readonly unknown[] } export type ServerAuthConfigFn = (ctx: ServerAuthContext) => ServerAuthConfig export type ClientAuthConfigFn = (ctx: ClientAuthContext) => ClientAuthConfig -// Module options for nuxt.config.ts export interface BetterAuthModuleOptions { /** Client-only mode - skip server setup for external auth backends */ clientOnly?: boolean @@ -58,7 +58,6 @@ export interface BetterAuthModuleOptions { } } -// Runtime config type for public.auth export interface AuthRuntimeConfig { redirects: { login: string, guest: string } useDatabase: boolean @@ -67,12 +66,15 @@ export interface AuthRuntimeConfig { session: { skipHydratedSsrGetSession: boolean } } -// Private runtime config (server-only) export interface AuthPrivateRuntimeConfig { secondaryStorage: boolean } -export function defineServerAuth(config: T | ((ctx: ServerAuthContext) => T)): (ctx: ServerAuthContext) => T { +export function defineServerAuth(config: R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: (ctx: ServerAuthContext) => R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: (ctx: ServerAuthContext) => R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: T | ((ctx: ServerAuthContext) => T)): (ctx: ServerAuthContext) => T { return typeof config === 'function' ? config : () => config } diff --git a/src/runtime/server/utils/auth.ts b/src/runtime/server/utils/auth.ts index 293178c..fe75424 100644 --- a/src/runtime/server/utils/auth.ts +++ b/src/runtime/server/utils/auth.ts @@ -1,4 +1,4 @@ -import type { Auth } from 'better-auth' +import type { Auth, BetterAuthOptions } from 'better-auth' import type { H3Event } from 'h3' import { createDatabase, db } from '#auth/database' import { createSecondaryStorage } from '#auth/secondary-storage' @@ -8,7 +8,7 @@ import { getRequestHost, getRequestProtocol } from 'h3' import { useRuntimeConfig } from 'nitropack/runtime' import { withoutProtocol } from 'ufo' -type AuthInstance = Auth> +type AuthInstance = Auth let _auth: AuthInstance | null = null let _baseURLInferenceLogged = false @@ -24,9 +24,7 @@ function normalizeLoopbackOrigin(origin: string): string { return url.origin } } - catch { - // Invalid URL is handled by validateURL. - } + catch {} return origin } @@ -48,11 +46,6 @@ function validateURL(url: string): string { } } -/** - * Get the Nitro origin URL. - * Adapted from nuxt-site-config by @harlan-zw - * @see https://github.com/harlan-zw/nuxt-site-config/blob/main/packages/kit/src/util.ts - */ function getNitroOrigin(e?: H3Event): string | undefined { const cert = process.env.NITRO_SSL_CERT const key = process.env.NITRO_SSL_KEY @@ -78,9 +71,7 @@ function getNitroOrigin(e?: H3Event): string | undefined { protocol = getRequestProtocol(e, { xForwardedProto: true }) || protocol } } - catch { - // JSON parse failed, continue with env fallbacks - } + catch {} if (!host) return undefined @@ -105,11 +96,9 @@ function getNitroOrigin(e?: H3Event): string | undefined { function getBaseURL(event?: H3Event): string { const config = useRuntimeConfig() - // 1. Explicit config (highest priority) if (config.public.siteUrl && typeof config.public.siteUrl === 'string') return validateURL(config.public.siteUrl) - // 2. Nitro origin detection (handles dev proxy, request headers) const nitroOrigin = getNitroOrigin(event) if (nitroOrigin) { const inferredBaseURL = validateURL(nitroOrigin) @@ -117,7 +106,6 @@ function getBaseURL(event?: H3Event): string { return inferredBaseURL } - // 3. Platform env vars (fallback for non-request contexts) if (process.env.VERCEL_URL) { const inferredBaseURL = validateURL(`https://${process.env.VERCEL_URL}`) logInferredBaseURL(inferredBaseURL, 'VERCEL_URL') @@ -134,7 +122,6 @@ function getBaseURL(event?: H3Event): string { return inferredBaseURL } - // 4. Dev fallback if (import.meta.dev) { const inferredBaseURL = 'http://localhost:3000' logInferredBaseURL(inferredBaseURL, 'development fallback') @@ -144,7 +131,6 @@ function getBaseURL(event?: H3Event): string { throw new Error('siteUrl required. Set NUXT_PUBLIC_SITE_URL.') } -/** Returns Better Auth instance. Pass event for accurate URL detection on first call. */ export function serverAuth(event?: H3Event): AuthInstance { if (_auth) return _auth @@ -156,12 +142,12 @@ export function serverAuth(event?: H3Event): AuthInstance { const userConfig = createServerAuth({ runtimeConfig, db }) _auth = betterAuth({ - ...userConfig, + ...(userConfig as unknown as BetterAuthOptions), ...(database && { database }), secondaryStorage: createSecondaryStorage(), secret: runtimeConfig.betterAuthSecret, baseURL: siteUrl, - }) + }) as AuthInstance return _auth } diff --git a/src/runtime/types.ts b/src/runtime/types.ts index ce2305d..2b69752 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -3,6 +3,7 @@ import type { AuthSession, AuthUser } from './types/augment' // Re-export augmentable types export type { AuthSession, AuthUser, ServerAuthContext, UserSessionComposable } from './types/augment' +export type { BetterAuthConfigFromServerConfig, SessionFieldsFromConfig, UserFieldsFromConfig } from './types/infer' // Re-export better-auth types for $Infer access export type { Auth, InferPluginTypes, InferSession, InferUser } from 'better-auth' diff --git a/src/runtime/types/infer.ts b/src/runtime/types/infer.ts new file mode 100644 index 0000000..24941b9 --- /dev/null +++ b/src/runtime/types/infer.ts @@ -0,0 +1,31 @@ +import type { BetterAuthOptions, BetterAuthPlugin, UnionToIntersection } from 'better-auth' +import type { InferFieldsOutput } from 'better-auth/db' + +export type PluginsFromConfig = C extends { plugins: infer P } + ? P + : C extends { plugins?: infer P } + ? P + : [] + +export type NormalizePlugins

= P extends readonly (infer T)[] + ? Array + : P extends (infer T)[] + ? Array + : BetterAuthPlugin[] + +export type BetterAuthConfigFromServerConfig = Omit & Omit & { + plugins?: NormalizePlugins> +} + +type InferModelFieldsFromPlugins = P extends readonly (infer Plugin)[] + ? UnionToIntersection : {}> + : P extends (infer Plugin)[] + ? UnionToIntersection : {}> + : {} + +type InferModelFieldsFromOptions = C extends { [K in M]: { additionalFields: infer F } } + ? InferFieldsOutput + : {} + +export type UserFieldsFromConfig = InferModelFieldsFromPlugins, 'user'> & InferModelFieldsFromOptions +export type SessionFieldsFromConfig = InferModelFieldsFromPlugins, 'session'> & InferModelFieldsFromOptions diff --git a/test/fixtures/type-infer-107/app/app.vue b/test/fixtures/type-infer-107/app/app.vue new file mode 100644 index 0000000..2bb142d --- /dev/null +++ b/test/fixtures/type-infer-107/app/app.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/type-infer-107/app/auth.config.ts b/test/fixtures/type-infer-107/app/auth.config.ts new file mode 100644 index 0000000..ce985ee --- /dev/null +++ b/test/fixtures/type-infer-107/app/auth.config.ts @@ -0,0 +1,3 @@ +import { defineClientAuth } from '../../../../src/runtime/config' + +export default defineClientAuth({}) diff --git a/test/fixtures/type-infer-107/nuxt.config.ts b/test/fixtures/type-infer-107/nuxt.config.ts new file mode 100644 index 0000000..4d5379e --- /dev/null +++ b/test/fixtures/type-infer-107/nuxt.config.ts @@ -0,0 +1,10 @@ +export default defineNuxtConfig({ + modules: ['../../../src/module'], + runtimeConfig: { + betterAuthSecret: 'test-secret-for-testing-only-32chars!', + public: { siteUrl: 'http://localhost:3000' }, + }, + routeRules: { + '/admin/**': { auth: { user: { role: 'admin', internalCode: 'x' } } }, + }, +}) diff --git a/test/fixtures/type-infer-107/server/auth.config.ts b/test/fixtures/type-infer-107/server/auth.config.ts new file mode 100644 index 0000000..b589243 --- /dev/null +++ b/test/fixtures/type-infer-107/server/auth.config.ts @@ -0,0 +1,34 @@ +import { defineServerAuth } from '../../../../src/runtime/config' + +function customAdminLikePlugin() { + return { + id: 'custom-admin-like', + $ERROR_CODES: { + BROKEN: 'Broken', + }, + schema: { + user: { + fields: { + role: { + type: 'string', + required: false, + input: false, + }, + }, + }, + }, + } as const +} + +export default defineServerAuth({ + emailAndPassword: { enabled: true }, + plugins: [customAdminLikePlugin()], + user: { + additionalFields: { + internalCode: { + type: 'string', + required: false, + }, + }, + }, +}) diff --git a/test/fixtures/type-infer-107/tsconfig.json b/test/fixtures/type-infer-107/tsconfig.json new file mode 100644 index 0000000..4b34df1 --- /dev/null +++ b/test/fixtures/type-infer-107/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "./.nuxt/tsconfig.json" +} diff --git a/test/type-infer-107.test.ts b/test/type-infer-107.test.ts new file mode 100644 index 0000000..251ddeb --- /dev/null +++ b/test/type-infer-107.test.ts @@ -0,0 +1,31 @@ +import { spawnSync } from 'node:child_process' +import { fileURLToPath } from 'node:url' +import { describe, expect, it } from 'vitest' + +const fixtureDir = fileURLToPath(new URL('./fixtures/type-infer-107', import.meta.url)) +const env = { + ...process.env, + BETTER_AUTH_SECRET: 'test-secret-for-testing-only-32chars', +} + +describe('type inference regression #107', () => { + it('typechecks routeRules user fields inferred from plugins/additionalFields', () => { + const prepare = spawnSync('npx', ['nuxi', 'prepare'], { + cwd: fixtureDir, + env, + encoding: 'utf8', + }) + expect(prepare.status, `nuxi prepare failed:\n${prepare.stdout}\n${prepare.stderr}`).toBe(0) + + const typecheck = spawnSync('npx', ['vue-tsc', '--noEmit', '--pretty', 'false', '-p', 'tsconfig.json'], { + cwd: fixtureDir, + env, + encoding: 'utf8', + }) + const output = `${typecheck.stdout}\n${typecheck.stderr}` + + expect(output).not.toContain(`is not assignable to type 'BetterAuthPlugin'`) + expect(output).not.toContain(`'role' does not exist in type`) + expect(output).not.toContain(`'internalCode' does not exist in type`) + }, 60_000) +}) From 3147c917e5592ea081e7a9dfefb1af6e555bc109 Mon Sep 17 00:00:00 2001 From: onmax Date: Thu, 12 Feb 2026 21:17:24 +0100 Subject: [PATCH 2/5] fix(types): preserve #107 auth inference --- playground/app/types/auth.d.ts | 9 ---- src/module/type-templates.ts | 43 +++++++++++++++---- src/runtime/config.ts | 10 ++++- test/fixtures/type-infer-107/app/app.vue | 3 ++ .../type-infer-107/app/auth.config.ts | 3 ++ test/fixtures/type-infer-107/nuxt.config.ts | 10 +++++ .../type-infer-107/server/auth.config.ts | 34 +++++++++++++++ test/fixtures/type-infer-107/tsconfig.json | 3 ++ test/type-infer-107.test.ts | 31 +++++++++++++ 9 files changed, 127 insertions(+), 19 deletions(-) delete mode 100644 playground/app/types/auth.d.ts create mode 100644 test/fixtures/type-infer-107/app/app.vue create mode 100644 test/fixtures/type-infer-107/app/auth.config.ts create mode 100644 test/fixtures/type-infer-107/nuxt.config.ts create mode 100644 test/fixtures/type-infer-107/server/auth.config.ts create mode 100644 test/fixtures/type-infer-107/tsconfig.json create mode 100644 test/type-infer-107.test.ts diff --git a/playground/app/types/auth.d.ts b/playground/app/types/auth.d.ts deleted file mode 100644 index 7cf40ce..0000000 --- a/playground/app/types/auth.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Augment AuthUser with plugin fields (admin, twoFactor) -declare module '#nuxt-better-auth' { - interface AuthUser { - role?: 'user' | 'admin' - twoFactorEnabled?: boolean - } -} - -export {} diff --git a/src/module/type-templates.ts b/src/module/type-templates.ts index 8192fd2..99a043f 100644 --- a/src/module/type-templates.ts +++ b/src/module/type-templates.ts @@ -37,31 +37,58 @@ declare module '#auth/database' { addTypeTemplate({ filename: 'types/nuxt-better-auth-infer.d.ts', getContents: () => ` -import type { InferUser, InferSession, InferPluginTypes } from 'better-auth' +import type { BetterAuthOptions, BetterAuthPlugin, InferPluginTypes, UnionToIntersection } from 'better-auth' +import type { InferFieldsOutput } from 'better-auth/db' import type { RuntimeConfig } from 'nuxt/schema' import type createServerAuth from '${serverConfigPath}' -type _Config = ReturnType +type _RawConfig = ReturnType +type _RawPlugins = _RawConfig extends { plugins: infer P } ? P : _RawConfig extends { plugins?: infer P } ? P : [] +type _NormalizedPlugins = _RawPlugins extends readonly (infer T)[] + ? Array + : _RawPlugins extends (infer T)[] + ? Array + : BetterAuthPlugin[] +type _Config = Omit & Omit<_RawConfig, 'plugins'> & { + plugins?: _NormalizedPlugins +} + +type _InferModelFieldsFromPlugins = P extends readonly (infer Plugin)[] + ? UnionToIntersection : {}> + : P extends (infer Plugin)[] + ? UnionToIntersection : {}> + : {} + +type _InferModelFieldsFromOptions = C extends { [K in M]: { additionalFields: infer F } } + ? InferFieldsOutput + : {} + +type _UserFallback = _InferModelFieldsFromPlugins<_RawPlugins, 'user'> & _InferModelFieldsFromOptions<_RawConfig, 'user'> +type _SessionFallback = _InferModelFieldsFromPlugins<_RawPlugins, 'session'> & _InferModelFieldsFromOptions<_RawConfig, 'session'> declare module '#nuxt-better-auth' { - interface AuthUser extends InferUser<_Config> {} - interface AuthSession extends InferSession<_Config> {} + interface AuthUser extends _UserFallback {} + interface AuthSession extends _SessionFallback {} interface ServerAuthContext { runtimeConfig: RuntimeConfig - ${hasHubDb ? `db: typeof import('@nuxthub/db')['db']` : ''} + db: ${hasHubDb ? `typeof import('@nuxthub/db')['db']` : 'unknown'} } type PluginTypes = InferPluginTypes<_Config> } interface _AugmentedServerAuthContext { runtimeConfig: RuntimeConfig - ${hasHubDb ? `db: typeof import('@nuxthub/db')['db']` : 'db: unknown'} + db: ${hasHubDb ? `typeof import('@nuxthub/db')['db']` : 'unknown'} } declare module '@onmax/nuxt-better-auth/config' { import type { BetterAuthOptions } from 'better-auth' - type ServerAuthConfig = Omit - export function defineServerAuth(config: T | ((ctx: _AugmentedServerAuthContext) => T)): (ctx: _AugmentedServerAuthContext) => T + type ServerAuthConfigBase = Omit + type ServerAuthConfigWithPlugins = ServerAuthConfigBase & { plugins: readonly unknown[] } + export function defineServerAuth(config: R): (ctx: _AugmentedServerAuthContext) => R + export function defineServerAuth(config: (ctx: _AugmentedServerAuthContext) => R): (ctx: _AugmentedServerAuthContext) => R + export function defineServerAuth(config: R): (ctx: _AugmentedServerAuthContext) => R + export function defineServerAuth(config: (ctx: _AugmentedServerAuthContext) => R): (ctx: _AugmentedServerAuthContext) => R } `, }, { nuxt: true, nitro: true, node: true }) diff --git a/src/runtime/config.ts b/src/runtime/config.ts index 26d6e3e..ee44382 100644 --- a/src/runtime/config.ts +++ b/src/runtime/config.ts @@ -12,8 +12,10 @@ export interface ClientAuthContext { siteUrl: string } -export type ServerAuthConfig = Omit +export type ServerAuthConfigBase = Omit +export type ServerAuthConfig = ServerAuthConfigBase export type ClientAuthConfig = Omit & { baseURL?: string } +type ServerAuthConfigWithPlugins = ServerAuthConfigBase & { plugins: readonly unknown[] } export type ServerAuthConfigFn = (ctx: ServerAuthContext) => ServerAuthConfig export type ClientAuthConfigFn = (ctx: ClientAuthContext) => ClientAuthConfig @@ -72,7 +74,11 @@ export interface AuthPrivateRuntimeConfig { secondaryStorage: boolean } -export function defineServerAuth(config: T | ((ctx: ServerAuthContext) => T)): (ctx: ServerAuthContext) => T { +export function defineServerAuth(config: R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: (ctx: ServerAuthContext) => R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: (ctx: ServerAuthContext) => R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: T | ((ctx: ServerAuthContext) => T)): (ctx: ServerAuthContext) => T { return typeof config === 'function' ? config : () => config } diff --git a/test/fixtures/type-infer-107/app/app.vue b/test/fixtures/type-infer-107/app/app.vue new file mode 100644 index 0000000..2bb142d --- /dev/null +++ b/test/fixtures/type-infer-107/app/app.vue @@ -0,0 +1,3 @@ + diff --git a/test/fixtures/type-infer-107/app/auth.config.ts b/test/fixtures/type-infer-107/app/auth.config.ts new file mode 100644 index 0000000..ce985ee --- /dev/null +++ b/test/fixtures/type-infer-107/app/auth.config.ts @@ -0,0 +1,3 @@ +import { defineClientAuth } from '../../../../src/runtime/config' + +export default defineClientAuth({}) diff --git a/test/fixtures/type-infer-107/nuxt.config.ts b/test/fixtures/type-infer-107/nuxt.config.ts new file mode 100644 index 0000000..4d5379e --- /dev/null +++ b/test/fixtures/type-infer-107/nuxt.config.ts @@ -0,0 +1,10 @@ +export default defineNuxtConfig({ + modules: ['../../../src/module'], + runtimeConfig: { + betterAuthSecret: 'test-secret-for-testing-only-32chars!', + public: { siteUrl: 'http://localhost:3000' }, + }, + routeRules: { + '/admin/**': { auth: { user: { role: 'admin', internalCode: 'x' } } }, + }, +}) diff --git a/test/fixtures/type-infer-107/server/auth.config.ts b/test/fixtures/type-infer-107/server/auth.config.ts new file mode 100644 index 0000000..b589243 --- /dev/null +++ b/test/fixtures/type-infer-107/server/auth.config.ts @@ -0,0 +1,34 @@ +import { defineServerAuth } from '../../../../src/runtime/config' + +function customAdminLikePlugin() { + return { + id: 'custom-admin-like', + $ERROR_CODES: { + BROKEN: 'Broken', + }, + schema: { + user: { + fields: { + role: { + type: 'string', + required: false, + input: false, + }, + }, + }, + }, + } as const +} + +export default defineServerAuth({ + emailAndPassword: { enabled: true }, + plugins: [customAdminLikePlugin()], + user: { + additionalFields: { + internalCode: { + type: 'string', + required: false, + }, + }, + }, +}) diff --git a/test/fixtures/type-infer-107/tsconfig.json b/test/fixtures/type-infer-107/tsconfig.json new file mode 100644 index 0000000..4b34df1 --- /dev/null +++ b/test/fixtures/type-infer-107/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "./.nuxt/tsconfig.json" +} diff --git a/test/type-infer-107.test.ts b/test/type-infer-107.test.ts new file mode 100644 index 0000000..251ddeb --- /dev/null +++ b/test/type-infer-107.test.ts @@ -0,0 +1,31 @@ +import { spawnSync } from 'node:child_process' +import { fileURLToPath } from 'node:url' +import { describe, expect, it } from 'vitest' + +const fixtureDir = fileURLToPath(new URL('./fixtures/type-infer-107', import.meta.url)) +const env = { + ...process.env, + BETTER_AUTH_SECRET: 'test-secret-for-testing-only-32chars', +} + +describe('type inference regression #107', () => { + it('typechecks routeRules user fields inferred from plugins/additionalFields', () => { + const prepare = spawnSync('npx', ['nuxi', 'prepare'], { + cwd: fixtureDir, + env, + encoding: 'utf8', + }) + expect(prepare.status, `nuxi prepare failed:\n${prepare.stdout}\n${prepare.stderr}`).toBe(0) + + const typecheck = spawnSync('npx', ['vue-tsc', '--noEmit', '--pretty', 'false', '-p', 'tsconfig.json'], { + cwd: fixtureDir, + env, + encoding: 'utf8', + }) + const output = `${typecheck.stdout}\n${typecheck.stderr}` + + expect(output).not.toContain(`is not assignable to type 'BetterAuthPlugin'`) + expect(output).not.toContain(`'role' does not exist in type`) + expect(output).not.toContain(`'internalCode' does not exist in type`) + }, 60_000) +}) From c8c9f11201f9f70fc427d9a62d048fa0cfa16d74 Mon Sep 17 00:00:00 2001 From: onmax Date: Fri, 13 Feb 2026 08:12:00 +0100 Subject: [PATCH 3/5] fix: restore defineServerAuth plugin typing --- src/module/type-templates.ts | 13 +++++----- src/runtime/config.ts | 16 ++++++------ .../type-infer-107/server/auth.config.ts | 5 +++- .../type-infer-107/tsconfig.type-check.json | 25 +++++++++++++++++++ .../type-infer-107/typecheck-target.ts | 14 +++++++++++ test/schema-generator.test.ts | 7 ++++++ test/type-infer-107.test.ts | 3 ++- 7 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 test/fixtures/type-infer-107/tsconfig.type-check.json create mode 100644 test/fixtures/type-infer-107/typecheck-target.ts diff --git a/src/module/type-templates.ts b/src/module/type-templates.ts index 99a043f..3b01bc3 100644 --- a/src/module/type-templates.ts +++ b/src/module/type-templates.ts @@ -82,13 +82,12 @@ interface _AugmentedServerAuthContext { } declare module '@onmax/nuxt-better-auth/config' { - import type { BetterAuthOptions } from 'better-auth' - type ServerAuthConfigBase = Omit - type ServerAuthConfigWithPlugins = ServerAuthConfigBase & { plugins: readonly unknown[] } - export function defineServerAuth(config: R): (ctx: _AugmentedServerAuthContext) => R - export function defineServerAuth(config: (ctx: _AugmentedServerAuthContext) => R): (ctx: _AugmentedServerAuthContext) => R - export function defineServerAuth(config: R): (ctx: _AugmentedServerAuthContext) => R - export function defineServerAuth(config: (ctx: _AugmentedServerAuthContext) => R): (ctx: _AugmentedServerAuthContext) => R + import type { BetterAuthOptions, BetterAuthPlugin } from 'better-auth' + type ServerAuthConfig = Omit & { + plugins?: readonly BetterAuthPlugin[] + } + export function defineServerAuth(config: R): (ctx: _AugmentedServerAuthContext) => R + export function defineServerAuth(config: (ctx: _AugmentedServerAuthContext) => R): (ctx: _AugmentedServerAuthContext) => R } `, }, { nuxt: true, nitro: true, node: true }) diff --git a/src/runtime/config.ts b/src/runtime/config.ts index ee44382..67ca804 100644 --- a/src/runtime/config.ts +++ b/src/runtime/config.ts @@ -1,4 +1,4 @@ -import type { BetterAuthOptions } from 'better-auth' +import type { BetterAuthOptions, BetterAuthPlugin } from 'better-auth' import type { BetterAuthClientOptions } from 'better-auth/client' import type { DatabaseProvider } from '../database-provider' import type { CasingOption } from '../schema-generator' @@ -12,10 +12,10 @@ export interface ClientAuthContext { siteUrl: string } -export type ServerAuthConfigBase = Omit -export type ServerAuthConfig = ServerAuthConfigBase +export type ServerAuthConfig = Omit & { + plugins?: readonly BetterAuthPlugin[] +} export type ClientAuthConfig = Omit & { baseURL?: string } -type ServerAuthConfigWithPlugins = ServerAuthConfigBase & { plugins: readonly unknown[] } export type ServerAuthConfigFn = (ctx: ServerAuthContext) => ServerAuthConfig export type ClientAuthConfigFn = (ctx: ClientAuthContext) => ClientAuthConfig @@ -74,11 +74,9 @@ export interface AuthPrivateRuntimeConfig { secondaryStorage: boolean } -export function defineServerAuth(config: R): (ctx: ServerAuthContext) => R -export function defineServerAuth(config: (ctx: ServerAuthContext) => R): (ctx: ServerAuthContext) => R -export function defineServerAuth(config: R): (ctx: ServerAuthContext) => R -export function defineServerAuth(config: (ctx: ServerAuthContext) => R): (ctx: ServerAuthContext) => R -export function defineServerAuth(config: T | ((ctx: ServerAuthContext) => T)): (ctx: ServerAuthContext) => T { +export function defineServerAuth(config: R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: (ctx: ServerAuthContext) => R): (ctx: ServerAuthContext) => R +export function defineServerAuth(config: T | ((ctx: ServerAuthContext) => T)): (ctx: ServerAuthContext) => T { return typeof config === 'function' ? config : () => config } diff --git a/test/fixtures/type-infer-107/server/auth.config.ts b/test/fixtures/type-infer-107/server/auth.config.ts index b589243..c55110d 100644 --- a/test/fixtures/type-infer-107/server/auth.config.ts +++ b/test/fixtures/type-infer-107/server/auth.config.ts @@ -4,7 +4,10 @@ function customAdminLikePlugin() { return { id: 'custom-admin-like', $ERROR_CODES: { - BROKEN: 'Broken', + BROKEN: { + code: 'BROKEN', + message: 'Broken', + }, }, schema: { user: { diff --git a/test/fixtures/type-infer-107/tsconfig.type-check.json b/test/fixtures/type-infer-107/tsconfig.type-check.json new file mode 100644 index 0000000..93d1fac --- /dev/null +++ b/test/fixtures/type-infer-107/tsconfig.type-check.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "preserve", + "target": "ESNext", + "moduleResolution": "bundler", + "strict": true, + "skipLibCheck": true, + "noEmit": true, + "lib": [ + "ESNext", + "DOM" + ], + "types": [], + "baseUrl": ".", + "paths": { + "#nuxt-better-auth": ["../../../src/runtime/types/augment"], + "#auth/server": ["./server/auth.config"], + "#auth/client": ["./app/auth.config"] + } + }, + "files": [ + "./typecheck-target.ts", + "./.nuxt/types/nuxt-better-auth-infer.d.ts" + ] +} diff --git a/test/fixtures/type-infer-107/typecheck-target.ts b/test/fixtures/type-infer-107/typecheck-target.ts new file mode 100644 index 0000000..1937fad --- /dev/null +++ b/test/fixtures/type-infer-107/typecheck-target.ts @@ -0,0 +1,14 @@ +import type { AuthUser } from '#nuxt-better-auth' + +const user: AuthUser = { + id: '1', + createdAt: new Date(), + updatedAt: new Date(), + email: 'a@b.c', + emailVerified: false, + name: 'n', + role: 'admin', + internalCode: 'x', +} + +void user diff --git a/test/schema-generator.test.ts b/test/schema-generator.test.ts index eba7521..bc6e456 100644 --- a/test/schema-generator.test.ts +++ b/test/schema-generator.test.ts @@ -140,6 +140,13 @@ describe('loadUserAuthConfig', () => { const result = await loadUserAuthConfig(configPath, false) expect(result).toEqual({ appName: 'Test', plugins: [] }) }) + + it('accepts readonly plugin tuples in object syntax defineServerAuth', async () => { + const configPath = join(TEST_DIR, 'readonly-object-config.ts') + writeFileSync(configPath, `const plugin = { id: 'test-plugin', schema: { user: { fields: {} } } } as const\nexport default defineServerAuth({ appName: 'Readonly', plugins: [plugin] as const })`) + const result = await loadUserAuthConfig(configPath, false) + expect(result).toEqual({ appName: 'Readonly', plugins: [{ id: 'test-plugin', schema: { user: { fields: {} } } }] }) + }) }) describe('defineServerAuth', () => { diff --git a/test/type-infer-107.test.ts b/test/type-infer-107.test.ts index 251ddeb..33ed278 100644 --- a/test/type-infer-107.test.ts +++ b/test/type-infer-107.test.ts @@ -17,11 +17,12 @@ describe('type inference regression #107', () => { }) expect(prepare.status, `nuxi prepare failed:\n${prepare.stdout}\n${prepare.stderr}`).toBe(0) - const typecheck = spawnSync('npx', ['vue-tsc', '--noEmit', '--pretty', 'false', '-p', 'tsconfig.json'], { + const typecheck = spawnSync('npx', ['vue-tsc', '--noEmit', '--pretty', 'false', '-p', 'tsconfig.type-check.json'], { cwd: fixtureDir, env, encoding: 'utf8', }) + expect(typecheck.status, `vue-tsc failed:\n${typecheck.stdout}\n${typecheck.stderr}`).toBe(0) const output = `${typecheck.stdout}\n${typecheck.stderr}` expect(output).not.toContain(`is not assignable to type 'BetterAuthPlugin'`) From d760ff9c69c8d47ef911aaff6cb6314e5504150f Mon Sep 17 00:00:00 2001 From: onmax Date: Fri, 13 Feb 2026 09:24:28 +0100 Subject: [PATCH 4/5] fix(test): sort fixture tsconfig keys --- .../type-infer-107/tsconfig.type-check.json | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/fixtures/type-infer-107/tsconfig.type-check.json b/test/fixtures/type-infer-107/tsconfig.type-check.json index 93d1fac..04e57dc 100644 --- a/test/fixtures/type-infer-107/tsconfig.type-check.json +++ b/test/fixtures/type-infer-107/tsconfig.type-check.json @@ -1,25 +1,25 @@ { "compilerOptions": { - "module": "preserve", "target": "ESNext", - "moduleResolution": "bundler", - "strict": true, - "skipLibCheck": true, - "noEmit": true, "lib": [ "ESNext", "DOM" ], - "types": [], "baseUrl": ".", + "module": "preserve", + "moduleResolution": "bundler", "paths": { - "#nuxt-better-auth": ["../../../src/runtime/types/augment"], + "#auth/client": ["./app/auth.config"], "#auth/server": ["./server/auth.config"], - "#auth/client": ["./app/auth.config"] - } + "#nuxt-better-auth": ["../../../src/runtime/types/augment"] + }, + "types": [], + "strict": true, + "noEmit": true, + "skipLibCheck": true }, "files": [ - "./typecheck-target.ts", - "./.nuxt/types/nuxt-better-auth-infer.d.ts" + "./.nuxt/types/nuxt-better-auth-infer.d.ts", + "./typecheck-target.ts" ] } From 2a35af31e46a600940da1573f07c95fb9ffe7d26 Mon Sep 17 00:00:00 2001 From: onmax Date: Fri, 13 Feb 2026 09:51:17 +0100 Subject: [PATCH 5/5] test: rename fixture folders for clarity --- test/{fixtures/basic => cases/core-auth}/.nuxtrc | 0 test/{fixtures/basic => cases/core-auth}/app/app.vue | 0 test/{fixtures/basic => cases/core-auth}/app/auth.config.ts | 0 .../basic => cases/core-auth}/app/pages/custom-protected.vue | 0 .../basic => cases/core-auth}/app/pages/dynamic/[...slug].vue | 0 test/{fixtures/basic => cases/core-auth}/app/pages/index.vue | 0 test/{fixtures/basic => cases/core-auth}/app/pages/login.vue | 0 .../{fixtures/basic => cases/core-auth}/app/pages/protected.vue | 0 test/{fixtures/basic => cases/core-auth}/nuxt.config.ts | 0 .../basic => cases/core-auth}/server/api/test/config.get.ts | 0 .../basic => cases/core-auth}/server/api/test/me.get.ts | 0 test/{fixtures/basic => cases/core-auth}/server/auth.config.ts | 0 .../basic => cases/core-auth}/server/plugins/init-db.ts | 0 test/{fixtures/no-db => cases/database-less}/.nuxtrc | 0 test/{fixtures/no-db => cases/database-less}/app/app.vue | 0 test/{fixtures/no-db => cases/database-less}/app/auth.config.ts | 0 .../{fixtures/no-db => cases/database-less}/app/pages/index.vue | 0 test/{fixtures/no-db => cases/database-less}/nuxt.config.ts | 0 .../no-db => cases/database-less}/server/api/test/config.get.ts | 0 .../no-db => cases/database-less}/server/auth.config.ts | 0 test/{fixtures/no-hub => cases/plugins-type-inference}/.nuxtrc | 0 .../type-infer-107 => cases/plugins-type-inference}/app/app.vue | 0 .../plugins-type-inference}/app/auth.config.ts | 0 .../plugins-type-inference}/nuxt.config.ts | 0 .../plugins-type-inference}/server/auth.config.ts | 0 .../plugins-type-inference}/tsconfig.json | 0 .../plugins-type-inference}/tsconfig.type-check.json | 0 .../plugins-type-inference}/typecheck-target.ts | 0 test/cases/without-nuxthub/.nuxtrc | 1 + test/{fixtures/no-hub => cases/without-nuxthub}/app/app.vue | 0 .../no-hub => cases/without-nuxthub}/app/auth.config.ts | 0 .../no-hub => cases/without-nuxthub}/app/pages/index.vue | 0 test/{fixtures/no-hub => cases/without-nuxthub}/nuxt.config.ts | 0 .../no-hub => cases/without-nuxthub}/server/auth.config.ts | 0 test/{type-infer-107.test.ts => infer-plugins-types.test.ts} | 2 +- test/module.test.ts | 2 +- test/no-db.test.ts | 2 +- test/no-hub.test.ts | 2 +- 38 files changed, 5 insertions(+), 4 deletions(-) rename test/{fixtures/basic => cases/core-auth}/.nuxtrc (100%) rename test/{fixtures/basic => cases/core-auth}/app/app.vue (100%) rename test/{fixtures/basic => cases/core-auth}/app/auth.config.ts (100%) rename test/{fixtures/basic => cases/core-auth}/app/pages/custom-protected.vue (100%) rename test/{fixtures/basic => cases/core-auth}/app/pages/dynamic/[...slug].vue (100%) rename test/{fixtures/basic => cases/core-auth}/app/pages/index.vue (100%) rename test/{fixtures/basic => cases/core-auth}/app/pages/login.vue (100%) rename test/{fixtures/basic => cases/core-auth}/app/pages/protected.vue (100%) rename test/{fixtures/basic => cases/core-auth}/nuxt.config.ts (100%) rename test/{fixtures/basic => cases/core-auth}/server/api/test/config.get.ts (100%) rename test/{fixtures/basic => cases/core-auth}/server/api/test/me.get.ts (100%) rename test/{fixtures/basic => cases/core-auth}/server/auth.config.ts (100%) rename test/{fixtures/basic => cases/core-auth}/server/plugins/init-db.ts (100%) rename test/{fixtures/no-db => cases/database-less}/.nuxtrc (100%) rename test/{fixtures/no-db => cases/database-less}/app/app.vue (100%) rename test/{fixtures/no-db => cases/database-less}/app/auth.config.ts (100%) rename test/{fixtures/no-db => cases/database-less}/app/pages/index.vue (100%) rename test/{fixtures/no-db => cases/database-less}/nuxt.config.ts (100%) rename test/{fixtures/no-db => cases/database-less}/server/api/test/config.get.ts (100%) rename test/{fixtures/no-db => cases/database-less}/server/auth.config.ts (100%) rename test/{fixtures/no-hub => cases/plugins-type-inference}/.nuxtrc (100%) rename test/{fixtures/type-infer-107 => cases/plugins-type-inference}/app/app.vue (100%) rename test/{fixtures/type-infer-107 => cases/plugins-type-inference}/app/auth.config.ts (100%) rename test/{fixtures/type-infer-107 => cases/plugins-type-inference}/nuxt.config.ts (100%) rename test/{fixtures/type-infer-107 => cases/plugins-type-inference}/server/auth.config.ts (100%) rename test/{fixtures/type-infer-107 => cases/plugins-type-inference}/tsconfig.json (100%) rename test/{fixtures/type-infer-107 => cases/plugins-type-inference}/tsconfig.type-check.json (100%) rename test/{fixtures/type-infer-107 => cases/plugins-type-inference}/typecheck-target.ts (100%) create mode 100644 test/cases/without-nuxthub/.nuxtrc rename test/{fixtures/no-hub => cases/without-nuxthub}/app/app.vue (100%) rename test/{fixtures/no-hub => cases/without-nuxthub}/app/auth.config.ts (100%) rename test/{fixtures/no-hub => cases/without-nuxthub}/app/pages/index.vue (100%) rename test/{fixtures/no-hub => cases/without-nuxthub}/nuxt.config.ts (100%) rename test/{fixtures/no-hub => cases/without-nuxthub}/server/auth.config.ts (100%) rename test/{type-infer-107.test.ts => infer-plugins-types.test.ts} (92%) diff --git a/test/fixtures/basic/.nuxtrc b/test/cases/core-auth/.nuxtrc similarity index 100% rename from test/fixtures/basic/.nuxtrc rename to test/cases/core-auth/.nuxtrc diff --git a/test/fixtures/basic/app/app.vue b/test/cases/core-auth/app/app.vue similarity index 100% rename from test/fixtures/basic/app/app.vue rename to test/cases/core-auth/app/app.vue diff --git a/test/fixtures/basic/app/auth.config.ts b/test/cases/core-auth/app/auth.config.ts similarity index 100% rename from test/fixtures/basic/app/auth.config.ts rename to test/cases/core-auth/app/auth.config.ts diff --git a/test/fixtures/basic/app/pages/custom-protected.vue b/test/cases/core-auth/app/pages/custom-protected.vue similarity index 100% rename from test/fixtures/basic/app/pages/custom-protected.vue rename to test/cases/core-auth/app/pages/custom-protected.vue diff --git a/test/fixtures/basic/app/pages/dynamic/[...slug].vue b/test/cases/core-auth/app/pages/dynamic/[...slug].vue similarity index 100% rename from test/fixtures/basic/app/pages/dynamic/[...slug].vue rename to test/cases/core-auth/app/pages/dynamic/[...slug].vue diff --git a/test/fixtures/basic/app/pages/index.vue b/test/cases/core-auth/app/pages/index.vue similarity index 100% rename from test/fixtures/basic/app/pages/index.vue rename to test/cases/core-auth/app/pages/index.vue diff --git a/test/fixtures/basic/app/pages/login.vue b/test/cases/core-auth/app/pages/login.vue similarity index 100% rename from test/fixtures/basic/app/pages/login.vue rename to test/cases/core-auth/app/pages/login.vue diff --git a/test/fixtures/basic/app/pages/protected.vue b/test/cases/core-auth/app/pages/protected.vue similarity index 100% rename from test/fixtures/basic/app/pages/protected.vue rename to test/cases/core-auth/app/pages/protected.vue diff --git a/test/fixtures/basic/nuxt.config.ts b/test/cases/core-auth/nuxt.config.ts similarity index 100% rename from test/fixtures/basic/nuxt.config.ts rename to test/cases/core-auth/nuxt.config.ts diff --git a/test/fixtures/basic/server/api/test/config.get.ts b/test/cases/core-auth/server/api/test/config.get.ts similarity index 100% rename from test/fixtures/basic/server/api/test/config.get.ts rename to test/cases/core-auth/server/api/test/config.get.ts diff --git a/test/fixtures/basic/server/api/test/me.get.ts b/test/cases/core-auth/server/api/test/me.get.ts similarity index 100% rename from test/fixtures/basic/server/api/test/me.get.ts rename to test/cases/core-auth/server/api/test/me.get.ts diff --git a/test/fixtures/basic/server/auth.config.ts b/test/cases/core-auth/server/auth.config.ts similarity index 100% rename from test/fixtures/basic/server/auth.config.ts rename to test/cases/core-auth/server/auth.config.ts diff --git a/test/fixtures/basic/server/plugins/init-db.ts b/test/cases/core-auth/server/plugins/init-db.ts similarity index 100% rename from test/fixtures/basic/server/plugins/init-db.ts rename to test/cases/core-auth/server/plugins/init-db.ts diff --git a/test/fixtures/no-db/.nuxtrc b/test/cases/database-less/.nuxtrc similarity index 100% rename from test/fixtures/no-db/.nuxtrc rename to test/cases/database-less/.nuxtrc diff --git a/test/fixtures/no-db/app/app.vue b/test/cases/database-less/app/app.vue similarity index 100% rename from test/fixtures/no-db/app/app.vue rename to test/cases/database-less/app/app.vue diff --git a/test/fixtures/no-db/app/auth.config.ts b/test/cases/database-less/app/auth.config.ts similarity index 100% rename from test/fixtures/no-db/app/auth.config.ts rename to test/cases/database-less/app/auth.config.ts diff --git a/test/fixtures/no-db/app/pages/index.vue b/test/cases/database-less/app/pages/index.vue similarity index 100% rename from test/fixtures/no-db/app/pages/index.vue rename to test/cases/database-less/app/pages/index.vue diff --git a/test/fixtures/no-db/nuxt.config.ts b/test/cases/database-less/nuxt.config.ts similarity index 100% rename from test/fixtures/no-db/nuxt.config.ts rename to test/cases/database-less/nuxt.config.ts diff --git a/test/fixtures/no-db/server/api/test/config.get.ts b/test/cases/database-less/server/api/test/config.get.ts similarity index 100% rename from test/fixtures/no-db/server/api/test/config.get.ts rename to test/cases/database-less/server/api/test/config.get.ts diff --git a/test/fixtures/no-db/server/auth.config.ts b/test/cases/database-less/server/auth.config.ts similarity index 100% rename from test/fixtures/no-db/server/auth.config.ts rename to test/cases/database-less/server/auth.config.ts diff --git a/test/fixtures/no-hub/.nuxtrc b/test/cases/plugins-type-inference/.nuxtrc similarity index 100% rename from test/fixtures/no-hub/.nuxtrc rename to test/cases/plugins-type-inference/.nuxtrc diff --git a/test/fixtures/type-infer-107/app/app.vue b/test/cases/plugins-type-inference/app/app.vue similarity index 100% rename from test/fixtures/type-infer-107/app/app.vue rename to test/cases/plugins-type-inference/app/app.vue diff --git a/test/fixtures/type-infer-107/app/auth.config.ts b/test/cases/plugins-type-inference/app/auth.config.ts similarity index 100% rename from test/fixtures/type-infer-107/app/auth.config.ts rename to test/cases/plugins-type-inference/app/auth.config.ts diff --git a/test/fixtures/type-infer-107/nuxt.config.ts b/test/cases/plugins-type-inference/nuxt.config.ts similarity index 100% rename from test/fixtures/type-infer-107/nuxt.config.ts rename to test/cases/plugins-type-inference/nuxt.config.ts diff --git a/test/fixtures/type-infer-107/server/auth.config.ts b/test/cases/plugins-type-inference/server/auth.config.ts similarity index 100% rename from test/fixtures/type-infer-107/server/auth.config.ts rename to test/cases/plugins-type-inference/server/auth.config.ts diff --git a/test/fixtures/type-infer-107/tsconfig.json b/test/cases/plugins-type-inference/tsconfig.json similarity index 100% rename from test/fixtures/type-infer-107/tsconfig.json rename to test/cases/plugins-type-inference/tsconfig.json diff --git a/test/fixtures/type-infer-107/tsconfig.type-check.json b/test/cases/plugins-type-inference/tsconfig.type-check.json similarity index 100% rename from test/fixtures/type-infer-107/tsconfig.type-check.json rename to test/cases/plugins-type-inference/tsconfig.type-check.json diff --git a/test/fixtures/type-infer-107/typecheck-target.ts b/test/cases/plugins-type-inference/typecheck-target.ts similarity index 100% rename from test/fixtures/type-infer-107/typecheck-target.ts rename to test/cases/plugins-type-inference/typecheck-target.ts diff --git a/test/cases/without-nuxthub/.nuxtrc b/test/cases/without-nuxthub/.nuxtrc new file mode 100644 index 0000000..c85c9d1 --- /dev/null +++ b/test/cases/without-nuxthub/.nuxtrc @@ -0,0 +1 @@ +setups.@onmax/nuxt-better-auth="0.0.2-alpha.21" \ No newline at end of file diff --git a/test/fixtures/no-hub/app/app.vue b/test/cases/without-nuxthub/app/app.vue similarity index 100% rename from test/fixtures/no-hub/app/app.vue rename to test/cases/without-nuxthub/app/app.vue diff --git a/test/fixtures/no-hub/app/auth.config.ts b/test/cases/without-nuxthub/app/auth.config.ts similarity index 100% rename from test/fixtures/no-hub/app/auth.config.ts rename to test/cases/without-nuxthub/app/auth.config.ts diff --git a/test/fixtures/no-hub/app/pages/index.vue b/test/cases/without-nuxthub/app/pages/index.vue similarity index 100% rename from test/fixtures/no-hub/app/pages/index.vue rename to test/cases/without-nuxthub/app/pages/index.vue diff --git a/test/fixtures/no-hub/nuxt.config.ts b/test/cases/without-nuxthub/nuxt.config.ts similarity index 100% rename from test/fixtures/no-hub/nuxt.config.ts rename to test/cases/without-nuxthub/nuxt.config.ts diff --git a/test/fixtures/no-hub/server/auth.config.ts b/test/cases/without-nuxthub/server/auth.config.ts similarity index 100% rename from test/fixtures/no-hub/server/auth.config.ts rename to test/cases/without-nuxthub/server/auth.config.ts diff --git a/test/type-infer-107.test.ts b/test/infer-plugins-types.test.ts similarity index 92% rename from test/type-infer-107.test.ts rename to test/infer-plugins-types.test.ts index 33ed278..03ab556 100644 --- a/test/type-infer-107.test.ts +++ b/test/infer-plugins-types.test.ts @@ -2,7 +2,7 @@ import { spawnSync } from 'node:child_process' import { fileURLToPath } from 'node:url' import { describe, expect, it } from 'vitest' -const fixtureDir = fileURLToPath(new URL('./fixtures/type-infer-107', import.meta.url)) +const fixtureDir = fileURLToPath(new URL('./cases/plugins-type-inference', import.meta.url)) const env = { ...process.env, BETTER_AUTH_SECRET: 'test-secret-for-testing-only-32chars', diff --git a/test/module.test.ts b/test/module.test.ts index 28d5a50..52ed6f8 100644 --- a/test/module.test.ts +++ b/test/module.test.ts @@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest' describe('nuxt-better-auth module', async () => { await setup({ - rootDir: fileURLToPath(new URL('./fixtures/basic', import.meta.url)), + rootDir: fileURLToPath(new URL('./cases/core-auth', import.meta.url)), }) describe('page rendering', () => { diff --git a/test/no-db.test.ts b/test/no-db.test.ts index 59176b2..b65774d 100644 --- a/test/no-db.test.ts +++ b/test/no-db.test.ts @@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest' describe('no-db mode (NuxtHub without database)', async () => { await setup({ - rootDir: fileURLToPath(new URL('./fixtures/no-db', import.meta.url)), + rootDir: fileURLToPath(new URL('./cases/database-less', import.meta.url)), }) it('renders home page without database', async () => { diff --git a/test/no-hub.test.ts b/test/no-hub.test.ts index 21c57e9..c670cd9 100644 --- a/test/no-hub.test.ts +++ b/test/no-hub.test.ts @@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest' describe('no-hub mode (without NuxtHub)', async () => { await setup({ - rootDir: fileURLToPath(new URL('./fixtures/no-hub', import.meta.url)), + rootDir: fileURLToPath(new URL('./cases/without-nuxthub', import.meta.url)), }) it('renders home page without NuxtHub', async () => {