diff --git a/e2e/smoke/test/fixtures/tsconfig-decelration/src/index.ts b/e2e/smoke/test/fixtures/tsconfig-decelration/src/index.ts index 0c136afcbd..aa2fc8072d 100644 --- a/e2e/smoke/test/fixtures/tsconfig-decelration/src/index.ts +++ b/e2e/smoke/test/fixtures/tsconfig-decelration/src/index.ts @@ -4,3 +4,39 @@ import { organization } from "better-auth/plugins"; export const auth = betterAuth({ plugins: [organization({})], }); + +auth.api + .getSession({ + headers: new Headers(), + }) + .catch(); + +auth.api + .getSession({ + headers: [] as [string, string][], + }) + .catch(); + +auth.api + .getSession({ + headers: {} as Record, + }) + .catch(); + +auth.api + .getSession({ + headers: new Headers(), + asResponse: true, + }) + .then((r: Response) => { + console.log(r); + }); + +auth.api + .getSession({ + headers: new Headers(), + returnHeaders: true, + }) + .then(({ headers }: { headers: Headers }) => { + console.log(headers); + }); diff --git a/e2e/smoke/test/fixtures/tsconfig-exact-optional-property-types/src/index.ts b/e2e/smoke/test/fixtures/tsconfig-exact-optional-property-types/src/index.ts index 5bf8cdf8ec..087468c15d 100644 --- a/e2e/smoke/test/fixtures/tsconfig-exact-optional-property-types/src/index.ts +++ b/e2e/smoke/test/fixtures/tsconfig-exact-optional-property-types/src/index.ts @@ -26,3 +26,39 @@ const authClient = createAuthClient({ authClient.useActiveOrganization(); authClient.useSession(); + +auth.api + .getSession({ + headers: new Headers(), + }) + .catch(); + +auth.api + .getSession({ + headers: [] as [string, string][], + }) + .catch(); + +auth.api + .getSession({ + headers: {} as Record, + }) + .catch(); + +auth.api + .getSession({ + headers: new Headers(), + asResponse: true, + }) + .then((r: Response) => { + console.log(r); + }); + +auth.api + .getSession({ + headers: new Headers(), + returnHeaders: true, + }) + .then(({ headers }: { headers: Headers }) => { + console.log(headers); + }); diff --git a/e2e/smoke/test/fixtures/tsconfig-verbatim-module-syntax-node10/src/index.ts b/e2e/smoke/test/fixtures/tsconfig-verbatim-module-syntax-node10/src/index.ts index 3d993d95f9..b9876140e5 100644 --- a/e2e/smoke/test/fixtures/tsconfig-verbatim-module-syntax-node10/src/index.ts +++ b/e2e/smoke/test/fixtures/tsconfig-verbatim-module-syntax-node10/src/index.ts @@ -2,7 +2,43 @@ import { betterAuth } from "better-auth"; import Database from "better-sqlite3"; import { expo } from "@better-auth/expo"; -betterAuth({ +const auth = betterAuth({ database: new Database("./sqlite.db"), plugins: [expo()], }); + +auth.api + .getSession({ + headers: new Headers(), + }) + .catch(); + +auth.api + .getSession({ + headers: [] as [string, string][], + }) + .catch(); + +auth.api + .getSession({ + headers: {} as Record, + }) + .catch(); + +auth.api + .getSession({ + headers: new Headers(), + asResponse: true, + }) + .then((r: Response) => { + console.log(r); + }); + +auth.api + .getSession({ + headers: new Headers(), + returnHeaders: true, + }) + .then(({ headers }: { headers: Headers }) => { + console.log(headers); + }); diff --git a/packages/better-auth/src/api/routes/session-api.test.ts b/packages/better-auth/src/api/routes/session-api.test.ts index c66043a671..0bfc1ec8f1 100644 --- a/packages/better-auth/src/api/routes/session-api.test.ts +++ b/packages/better-auth/src/api/routes/session-api.test.ts @@ -612,39 +612,3 @@ describe("cookie cache", async () => { expect(fn).toHaveBeenCalledTimes(5); }); }); - -describe("getSession type tests", async () => { - const { auth } = await getTestInstance(); - - it("has parameters", () => { - type Params = Parameters[0]["headers"]; - - expectTypeOf().toEqualTypeOf< - [string, string][] | Record | Headers - >(); - }); - - it("can return a response", () => { - type Returns = Awaited>>; - - expectTypeOf<{ returns: Returns }>().toMatchObjectType<{ - returns: Response; - }>(); - }); - - it("can return headers", () => { - type Returns = Awaited>>; - - expectTypeOf<{ returns: Returns["headers"] }>().toMatchObjectType<{ - returns: Headers; - }>(); - }); - - it("asResponse takes prescedence", () => { - type Returns = Awaited>>; - - expectTypeOf<{ returns: Returns }>().toMatchObjectType<{ - returns: Response; - }>(); - }); -}); diff --git a/packages/better-auth/src/api/to-auth-endpoints.ts b/packages/better-auth/src/api/to-auth-endpoints.ts index 2d6586cdf0..19cc354258 100644 --- a/packages/better-auth/src/api/to-auth-endpoints.ts +++ b/packages/better-auth/src/api/to-auth-endpoints.ts @@ -27,10 +27,9 @@ const defuReplaceArrays = createDefu((obj, key, value) => { } }); -export function toAuthEndpoints>( - endpoints: E, - ctx: AuthContext | Promise, -) { +export function toAuthEndpoints< + const E extends Record>, +>(endpoints: E, ctx: AuthContext | Promise): E { const api: Record< string, (( @@ -98,7 +97,7 @@ export function toAuthEndpoints>( internalContext.asResponse = false; internalContext.returnHeaders = true; const result = (await runWithEndpointContext(internalContext, () => - endpoint(internalContext as any), + (endpoint as any)(internalContext as any), ).catch((e: any) => { if (e instanceof APIError) { /** @@ -158,7 +157,7 @@ export function toAuthEndpoints>( api[key].path = endpoint.path; api[key].options = endpoint.options; } - return api as E; + return api as unknown as E; } async function runBeforeHooks( diff --git a/packages/better-auth/src/plugins/two-factor/types.ts b/packages/better-auth/src/plugins/two-factor/types.ts index 3574352d10..0cf4e127f1 100644 --- a/packages/better-auth/src/plugins/two-factor/types.ts +++ b/packages/better-auth/src/plugins/two-factor/types.ts @@ -1,5 +1,5 @@ import type { User } from "../../types"; -import type { AuthEndpoint } from "@better-auth/core/api"; +import type { BetterAuthPlugin } from "@better-auth/core"; import type { LiteralString } from "../../types/helper"; import type { BackupCodeOptions } from "./backup-codes"; import type { OTPOptions } from "./otp"; @@ -44,7 +44,7 @@ export interface UserWithTwoFactor extends User { export interface TwoFactorProvider { id: LiteralString; - endpoints?: Record; + endpoints?: BetterAuthPlugin["endpoints"]; } export interface TwoFactorTable { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0797689288..06d6771c62 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,8 +10,8 @@ catalogs: specifier: 1.1.18 version: 1.1.18 better-call: - specifier: 1.0.19 - version: 1.0.19 + specifier: 1.0.23 + version: 1.0.23 tsdown: specifier: ^0.15.6 version: 0.15.6 @@ -322,7 +322,7 @@ importers: version: link:../../packages/better-auth better-call: specifier: 'catalog:' - version: 1.0.19 + version: 1.0.23 better-sqlite3: specifier: ^12.2.0 version: 12.4.1 @@ -905,7 +905,7 @@ importers: version: 13.1.2 better-call: specifier: 'catalog:' - version: 1.0.19 + version: 1.0.23 defu: specifier: ^6.1.4 version: 6.1.4 @@ -1145,7 +1145,7 @@ importers: version: 7.6.13 better-call: specifier: 'catalog:' - version: 1.0.19 + version: 1.0.23 better-sqlite3: specifier: ^12.4.1 version: 12.4.1 @@ -1234,7 +1234,7 @@ importers: version: link:../better-auth better-call: specifier: 'catalog:' - version: 1.0.19 + version: 1.0.23 body-parser: specifier: ^2.2.0 version: 2.2.0 @@ -1262,7 +1262,7 @@ importers: version: link:../better-auth better-call: specifier: 'catalog:' - version: 1.0.19 + version: 1.0.23 stripe: specifier: ^18.5.0 version: 18.5.0(@types/node@24.7.2) @@ -6620,8 +6620,8 @@ packages: resolution: {integrity: sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==} engines: {node: '>= 0.8'} - better-call@1.0.19: - resolution: {integrity: sha512-sI3GcA1SCVa3H+CDHl8W8qzhlrckwXOTKhqq3OOPXjgn5aTOMIqGY34zLY/pHA6tRRMjTUC3lz5Mi7EbDA24Kw==} + better-call@1.0.23: + resolution: {integrity: sha512-t7P/huToNS89LHbuRPrrmdf2Dh9T+fXpEfoFGgadyzOS1AulAP/U/H2TDx/wR0kML4AL+V/lcM1XNeVL2oMV4A==} better-opn@3.0.2: resolution: {integrity: sha512-aVNobHnJqLiUelTaHat9DZ1qM2w0C0Eym4LPI/3JxOnSokGVdsl1T1kN7TFvsEAD8G47A6VKQ0TVHqbBnYMJlQ==} @@ -17498,7 +17498,9 @@ snapshots: metro-runtime: 0.83.3 transitivePeerDependencies: - '@babel/core' + - bufferutil - supports-color + - utf-8-validate optional: true '@react-native/normalize-colors@0.74.89': {} @@ -19513,7 +19515,7 @@ snapshots: dependencies: safe-buffer: 5.1.2 - better-call@1.0.19: + better-call@1.0.23: dependencies: '@better-auth/utils': 0.3.0 '@better-fetch/fetch': 1.1.18 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 81f7c6b590..53b0be5cf7 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -6,7 +6,7 @@ packages: catalog: '@better-fetch/fetch': 1.1.18 - better-call: 1.0.19 + better-call: 1.0.23 typescript: ^5.9.2 tsdown: ^0.15.6 vitest: ^3.2.4