From 0ceda4063d546ec84b3737b6c846bbc212b0a484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paola=20Estefan=C3=ADa=20de=20Campos?= <84341268+Paola3stefania@users.noreply.github.com> Date: Tue, 13 Jan 2026 00:43:25 +0100 Subject: [PATCH] fix(client): add `refetch` to `useSession` for all clients (#7255) --- .../better-auth/src/client/client.test.ts | 154 ++++++++++++++++++ .../better-auth/src/client/solid/index.ts | 4 + .../better-auth/src/client/svelte/index.ts | 4 + packages/better-auth/src/client/vanilla.ts | 5 + packages/better-auth/src/client/vue/index.ts | 4 + 5 files changed, 171 insertions(+) diff --git a/packages/better-auth/src/client/client.test.ts b/packages/better-auth/src/client/client.test.ts index e34cce9e1c..80a3b048a2 100644 --- a/packages/better-auth/src/client/client.test.ts +++ b/packages/better-auth/src/client/client.test.ts @@ -407,6 +407,160 @@ describe("type", () => { }>(); }); + it("should support refetch with query parameters - solid", () => { + const client = createSolidClient({ + plugins: [testClientPlugin()], + baseURL: "http://localhost:3000", + fetchOptions: { + customFetchImpl: async (url, init) => { + return new Response(); + }, + }, + }); + + type UseSessionReturn = ReturnType>; + expectTypeOf().toMatchTypeOf<{ + data: { + user: { + id: string; + email: string; + emailVerified: boolean; + name: string; + createdAt: Date; + updatedAt: Date; + image?: string | undefined | null; + testField4: string; + testField?: string | undefined | null; + testField2?: number | undefined | null; + }; + session: Session; + } | null; + isPending: boolean; + isRefetching: boolean; + error: BetterFetchError | null; + refetch: ( + queryParams?: { query?: SessionQueryParams } | undefined, + ) => Promise; + }>(); + }); + + it("should support refetch with query parameters - svelte", () => { + const client = createSvelteClient({ + plugins: [testClientPlugin()], + baseURL: "http://localhost:3000", + fetchOptions: { + customFetchImpl: async (url, init) => { + return new Response(); + }, + }, + }); + + type UseSessionAtom = ReturnType; + type UseSessionReturn = ReturnType; + expectTypeOf().toMatchTypeOf<{ + data: { + user: { + id: string; + email: string; + emailVerified: boolean; + name: string; + createdAt: Date; + updatedAt: Date; + image?: string | undefined | null; + testField4: string; + testField?: string | undefined | null; + testField2?: number | undefined | null; + }; + session: Session; + } | null; + isPending: boolean; + isRefetching: boolean; + error: BetterFetchError | null; + refetch: ( + queryParams?: { query?: SessionQueryParams } | undefined, + ) => Promise; + }>(); + }); + + it("should support refetch with query parameters - vue", () => { + const client = createVueClient({ + plugins: [testClientPlugin()], + baseURL: "http://localhost:3000", + fetchOptions: { + customFetchImpl: async (url, init) => { + return new Response(); + }, + }, + }); + + // Test the function signature directly to avoid overload resolution issues + expectTypeOf(client.useSession).toMatchTypeOf< + () => Readonly< + Ref<{ + data: { + user: { + id: string; + email: string; + emailVerified: boolean; + name: string; + createdAt: Date; + updatedAt: Date; + image?: string | undefined | null; + testField4: string; + testField?: string | undefined | null; + testField2?: number | undefined | null; + }; + session: Session; + } | null; + isPending: boolean; + isRefetching: boolean; + error: BetterFetchError | null; + refetch: ( + queryParams?: { query?: SessionQueryParams } | undefined, + ) => Promise; + }> + > + >(); + }); + + it("should support refetch with query parameters - vanilla", () => { + const client = createVanillaClient({ + plugins: [testClientPlugin()], + baseURL: "http://localhost:3000", + fetchOptions: { + customFetchImpl: async (url, init) => { + return new Response(); + }, + }, + }); + + type UseSessionAtom = typeof client.useSession; + type UseSessionReturn = ReturnType; + expectTypeOf().toMatchTypeOf<{ + data: { + user: { + id: string; + email: string; + emailVerified: boolean; + name: string; + createdAt: Date; + updatedAt: Date; + image?: string | undefined | null; + testField4: string; + testField?: string | undefined | null; + testField2?: number | undefined | null; + }; + session: Session; + } | null; + isPending: boolean; + isRefetching: boolean; + error: BetterFetchError | null; + refetch: ( + queryParams?: { query?: SessionQueryParams } | undefined, + ) => Promise; + }>(); + }); + it("should infer $ERROR_CODES with multiple plugins", () => { const client = createReactClient({ plugins: [ diff --git a/packages/better-auth/src/client/solid/index.ts b/packages/better-auth/src/client/solid/index.ts index b3655f0a81..c428569f97 100644 --- a/packages/better-auth/src/client/solid/index.ts +++ b/packages/better-auth/src/client/solid/index.ts @@ -17,6 +17,7 @@ import type { InferClientAPI, InferErrorCodes, IsSignal, + SessionQueryParams, } from "../types"; import { useStore } from "./solid-store"; @@ -87,6 +88,9 @@ export function createAuthClient