fix(client): add refetch to useSession for all clients (#7255)

This commit is contained in:
Paola Estefanía de Campos
2026-01-13 00:43:25 +01:00
committed by Alex Yang
parent 00de333265
commit 0ceda4063d
5 changed files with 171 additions and 0 deletions

View File

@@ -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<ReturnType<typeof client.useSession>>;
expectTypeOf<UseSessionReturn>().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<void>;
}>();
});
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<typeof client.useSession>;
type UseSessionReturn = ReturnType<UseSessionAtom["get"]>;
expectTypeOf<UseSessionReturn>().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<void>;
}>();
});
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<void>;
}>
>
>();
});
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<UseSessionAtom["get"]>;
expectTypeOf<UseSessionReturn>().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<void>;
}>();
});
it("should infer $ERROR_CODES with multiple plugins", () => {
const client = createReactClient({
plugins: [

View File

@@ -17,6 +17,7 @@ import type {
InferClientAPI,
InferErrorCodes,
IsSignal,
SessionQueryParams,
} from "../types";
import { useStore } from "./solid-store";
@@ -87,6 +88,9 @@ export function createAuthClient<Option extends BetterAuthClientOptions>(
isPending: boolean;
isRefetching: boolean;
error: BetterFetchError | null;
refetch: (
queryParams?: { query?: SessionQueryParams } | undefined,
) => Promise<void>;
}>;
$Infer: {
Session: NonNullable<Session>;

View File

@@ -17,6 +17,7 @@ import type {
InferClientAPI,
InferErrorCodes,
IsSignal,
SessionQueryParams,
} from "../types";
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
@@ -85,6 +86,9 @@ export function createAuthClient<Option extends BetterAuthClientOptions>(
error: BetterFetchError | null;
isPending: boolean;
isRefetching: boolean;
refetch: (
queryParams?: { query?: SessionQueryParams } | undefined,
) => Promise<void>;
}>;
$fetch: typeof $fetch;
$store: typeof $store;

View File

@@ -17,6 +17,7 @@ import type {
InferClientAPI,
InferErrorCodes,
IsSignal,
SessionQueryParams,
} from "./types";
type InferResolvedHooks<O extends BetterAuthClientOptions> = O extends {
@@ -84,6 +85,10 @@ export function createAuthClient<Option extends BetterAuthClientOptions>(
data: Session;
error: BetterFetchError | null;
isPending: boolean;
isRefetching: boolean;
refetch: (
queryParams?: { query?: SessionQueryParams } | undefined,
) => Promise<void>;
}>;
$fetch: typeof $fetch;
$store: typeof $store;

View File

@@ -17,6 +17,7 @@ import type {
InferClientAPI,
InferErrorCodes,
IsSignal,
SessionQueryParams,
} from "../types";
import { useStore } from "./vue-store";
@@ -80,6 +81,9 @@ export function createAuthClient<Option extends BetterAuthClientOptions>(
isPending: boolean;
isRefetching: boolean;
error: BetterFetchError | null;
refetch: (
queryParams?: { query?: SessionQueryParams } | undefined,
) => Promise<void>;
}>
>;
function useSession<F extends (...args: any) => any>(