@better-auth-ui/core
Version:
Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.
66 lines (65 loc) • 3.86 kB
TypeScript
import { DataTag, QueryClient, QueryOptions } from '@tanstack/query-core';
import { APIError } from 'better-auth';
import { AuthServer } from '../../../lib/auth-server';
export type AccountInfoData<TAuth extends AuthServer = AuthServer> = Awaited<ReturnType<TAuth["api"]["accountInfo"]>>;
export type AccountInfoParams<TAuth extends AuthServer> = Parameters<TAuth["api"]["accountInfo"]>[0];
export type AccountInfo<TAuth extends AuthServer = AuthServer> = NonNullable<AccountInfoData<TAuth>>;
/**
* Query options factory for provider-specific account info.
*
* @param auth - The Better Auth server instance.
* @param userId - The signed-in user's ID. Used for cache partitioning so
* the key matches the client-side `accountInfoOptions` for SSR hydration.
* @param params - Parameters forwarded to `auth.api.accountInfo`.
*/
export declare function accountInfoOptions<TAuth extends AuthServer>(auth: TAuth, userId: string, params: AccountInfoParams<TAuth>): QueryOptions<Awaited<ReturnType<TAuth["api"]["accountInfo"]>>, APIError, Awaited<ReturnType<TAuth["api"]["accountInfo"]>>, readonly ["auth", "user", string | undefined, "accountInfo", NonNullable<{
accountId: string;
userId?: string | undefined;
} | {
useAccountCookie: true;
userId?: string | undefined;
}> | null], never> & {
queryKey: DataTag<readonly ["auth", "user", string | undefined, "accountInfo", NonNullable<{
accountId: string;
userId?: string | undefined;
} | {
useAccountCookie: true;
userId?: string | undefined;
}> | null], Awaited<ReturnType<TAuth["api"]["accountInfo"]>>, APIError>;
};
/**
* Get the current user's provider-specific account info from the query
* cache, calling `fetchAccountInfo` under the hood if no cached entry
* exists. Resolves with the data, making it suitable for reading directly
* in a server component.
*
* @param queryClient - The React Query client used for SSR hydration.
* @param auth - The Better Auth server instance.
* @param userId - The signed-in user's ID, used for cache partitioning.
* @param params - Parameters forwarded to `auth.api.accountInfo`.
*/
export declare const ensureAccountInfo: <TAuth extends AuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: AccountInfoParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["accountInfo"]>>>;
/**
* Prefetch the current user's provider-specific account info into the query
* cache. Behaves like `fetchAccountInfo`, but does not throw on error and
* does not return the data — use this when you only need the value to be
* available after hydration.
*
* @param queryClient - The React Query client used for SSR hydration.
* @param auth - The Better Auth server instance.
* @param userId - The signed-in user's ID, used for cache partitioning.
* @param params - Parameters forwarded to `auth.api.accountInfo`.
*/
export declare const prefetchAccountInfo: <TAuth extends AuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: AccountInfoParams<TAuth>) => Promise<void>;
/**
* Fetch and cache the current user's provider-specific account info,
* 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 used for SSR hydration.
* @param auth - The Better Auth server instance.
* @param userId - The signed-in user's ID, used for cache partitioning.
* @param params - Parameters forwarded to `auth.api.accountInfo`.
*/
export declare const fetchAccountInfo: <TAuth extends AuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: AccountInfoParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["accountInfo"]>>>;