From f2226df19c152ecb94d2cc5dfdcce2b3d77be5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paola=20Estefan=C3=ADa=20de=20Campos?= Date: Sun, 11 Jan 2026 01:36:59 +0100 Subject: [PATCH] feat: add refecth to all clients --- .../better-auth/src/client/client.test.ts | 151 ++++++++++++++++++ .../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, 168 insertions(+) diff --git a/packages/better-auth/src/client/client.test.ts b/packages/better-auth/src/client/client.test.ts index 4ea2d1046b..03d4c136f5 100644 --- a/packages/better-auth/src/client/client.test.ts +++ b/packages/better-auth/src/client/client.test.ts @@ -407,6 +407,157 @@ 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(); + }, + }, + }); + + type UseSessionRef = ReturnType; + type UseSessionReturn = UseSessionRef["value"]; + 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 - 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