diff --git a/docs/content/5.api/1.composables.md b/docs/content/5.api/1.composables.md index 2fe8afd..184047a 100644 --- a/docs/content/5.api/1.composables.md +++ b/docs/content/5.api/1.composables.md @@ -228,7 +228,7 @@ const { data: customerById } = await useLazyFetch('/api/auth/customer/123/state' customerById.value?.customerId.toUpperCase() ``` -Global `$fetch` keeps Nitro `InternalApi` response inference, but path autocomplete is best on `useFetch`/`useLazyFetch` and `useAuthRequestFetch`. +Global `$fetch` is not augmented by this module; use `useAuthRequestFetch()` for typed auth endpoint payloads with request-scoped cookies. ```ts [pages/app.vue] const requestFetch = useAuthRequestFetch() diff --git a/src/module/type-templates.ts b/src/module/type-templates.ts index 122f3fe..f75fcc8 100644 --- a/src/module/type-templates.ts +++ b/src/module/type-templates.ts @@ -320,7 +320,6 @@ declare module 'nitropack' { interface NitroRouteConfig { auth?: import('${runtimeTypesPath}').AuthMeta } - interface InternalApi extends _GeneratedAuthInternalApi {} } declare module 'nitropack/types' { interface NitroRouteRules { @@ -329,7 +328,6 @@ declare module 'nitropack/types' { interface NitroRouteConfig { auth?: import('${runtimeTypesPath}').AuthMeta } - interface InternalApi extends _GeneratedAuthInternalApi {} } declare module 'nitro/types' { interface NitroRouteRules { @@ -338,7 +336,6 @@ declare module 'nitro/types' { interface NitroRouteConfig { auth?: import('${runtimeTypesPath}').AuthMeta } - interface InternalApi extends _GeneratedAuthInternalApi {} } export {} `, diff --git a/test/cases/nitro-endpoints-type-inference/typecheck-target.ts b/test/cases/nitro-endpoints-type-inference/typecheck-target.ts index 8a2eb1a..f479d3c 100644 --- a/test/cases/nitro-endpoints-type-inference/typecheck-target.ts +++ b/test/cases/nitro-endpoints-type-inference/typecheck-target.ts @@ -1,38 +1,16 @@ import type { Base$Fetch } from 'nitropack/types' -import type { AuthApiEndpointPath, AuthApiEndpointResponse } from '#nuxt-better-auth' +import type { AuthApiEndpointPath } from '#nuxt-better-auth' declare const requestFetch: Base$Fetch type CustomerStatePath = Extract const customerStatePath: CustomerStatePath = '/api/auth/customer/state' -async function assertEndpointInference() { +async function assertNoGlobalEndpointInference() { const customerState = await requestFetch('/api/auth/customer/state') + // @ts-expect-error use useAuthRequestFetch for typed auth endpoint payloads customerState.activeSubscriptions[0]?.toUpperCase() - customerState.hasBillingIssue.valueOf() - // @ts-expect-error no unknown key - void customerState.missingField - - const customerViaHelper: AuthApiEndpointResponse<'/api/auth/customer/state'> = customerState - void customerViaHelper - - const customerSessionGet = await requestFetch('/api/auth/customer/session') - const customerSessionPost = await requestFetch('/api/auth/customer/session', { method: 'POST' }) - customerSessionGet.ok.valueOf() - customerSessionPost.ok.valueOf() - - const session = await requestFetch('/api/auth/get-session') - if (session) { - void session.user.id - void session.session.expiresAt - } - // @ts-expect-error get-session can be null - const shouldFailNullability: { user: { id: string } } = session - void shouldFailNullability - - const sessionViaHelper: AuthApiEndpointResponse<'/api/auth/get-session', 'get'> = session - void sessionViaHelper } void customerStatePath -void assertEndpointInference +void assertNoGlobalEndpointInference diff --git a/test/infer-nitro-endpoints-types.test.ts b/test/infer-nitro-endpoints-types.test.ts index e488e4b..bc811ee 100644 --- a/test/infer-nitro-endpoints-types.test.ts +++ b/test/infer-nitro-endpoints-types.test.ts @@ -8,8 +8,8 @@ const env = { BETTER_AUTH_SECRET: 'test-secret-for-testing-only-32chars', } -describe('typed nitro route inference #194', () => { - it('typechecks generated InternalApi endpoint inference for /api/auth routes', () => { +describe('nitro route inference', () => { + it('does not augment global InternalApi with /api/auth routes', () => { const prepare = spawnSync('npx', ['nuxi', 'prepare'], { cwd: fixtureDir, env,