import { DataTag, QueryClient } from '@tanstack/react-query'; import { BetterFetchError } from 'better-auth/react'; import { AuthClient, InferData } from '../../lib/auth-client'; export type SessionData = InferData; export type Session = NonNullable>; export type SessionParams = Parameters[0]; export type SessionOptions = Omit>, "queryKey" | "queryFn">; /** * Query options factory for the current session. * * Shares a query key with the server-side `sessionOptions` so that data * prefetched during SSR hydrates seamlessly into the client cache. * * @param authClient - The Better Auth client. * @param params - Parameters forwarded to `authClient.getSession`. */ export declare function sessionOptions(authClient: TAuthClient, params?: SessionParams): (import('@tanstack/query-core').OmitKeyof, BetterFetchError, InferData, readonly ["auth", "getSession"]>, "queryFn"> & { queryFn?: import('@tanstack/query-core').QueryFunction, readonly ["auth", "getSession"], never> | undefined; } & { queryKey: readonly ["auth", "getSession"] & { [dataTagSymbol]: InferData; [dataTagErrorSymbol]: BetterFetchError; }; }) & { queryKey: DataTag, BetterFetchError>; }; /** * Get the current session from the query cache, calling `fetchSession` under * the hood if no cached entry exists. Resolves with the session data, making * it ideal for loaders or `beforeLoad` guards. * * @param queryClient - The React Query client. * @param authClient - The Better Auth client. * @param params - Parameters forwarded to `authClient.getSession`. */ export declare const ensureSession: (queryClient: QueryClient, authClient: TAuthClient, params?: SessionParams) => Promise>; /** * Prefetch the current session into the query cache. Behaves like * `fetchSession`, but does not throw on error and does not return the data — * use this to warm the cache without blocking navigation. * * @param queryClient - The React Query client. * @param authClient - The Better Auth client. * @param params - Parameters forwarded to `authClient.getSession`. */ export declare const prefetchSession: (queryClient: QueryClient, authClient: TAuthClient, params?: SessionParams) => Promise; /** * Fetch and cache the current session, resolving with the data or throwing * on error. If a cached entry exists and is neither invalidated nor older * than `staleTime`, the cached value is returned without a network call; * otherwise the latest data is fetched. * * @param queryClient - The React Query client. * @param authClient - The Better Auth client. * @param params - Parameters forwarded to `authClient.getSession`. */ export declare const fetchSession: (queryClient: QueryClient, authClient: TAuthClient, params?: SessionParams) => Promise>; export type UseSessionOptions = SessionOptions & SessionParams; /** * Subscribe to the current session via TanStack Query. * * Shares a query key with the server-side `sessionOptions`, so SSR-hydrated * session data is reused from the cache without an immediate refetch. * * @param authClient - The Better Auth client. * @param options - `getSession` params (`query`, `fetchOptions`) merged * with `useQuery` options (e.g. `enabled`, `staleTime`, `select`). * @param queryClient - Optional custom `QueryClient`. Defaults to the client * from the nearest `QueryClientProvider`. */ export declare function useSession(authClient: TAuthClient, options?: UseSessionOptions, queryClient?: QueryClient): import('@tanstack/react-query').UseQueryResult>, BetterFetchError>;