@better-auth-ui/core
Version:
Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.
63 lines (62 loc) • 3.8 kB
TypeScript
import { DataTag, QueryClient, QueryOptions } from '@tanstack/query-core';
import { APIError } from 'better-auth';
import { ApiKeyAuthServer } from '../../../plugins/api-key/server/api-key-auth-server';
export type ListApiKeysData<TAuth extends ApiKeyAuthServer = ApiKeyAuthServer> = Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>;
export type ListedApiKey<TAuth extends ApiKeyAuthServer = ApiKeyAuthServer> = NonNullable<ListApiKeysData<TAuth>>["apiKeys"][number];
export type ListApiKeysParams<TAuth extends ApiKeyAuthServer = ApiKeyAuthServer> = Parameters<TAuth["api"]["listApiKeys"]>[0];
/**
* Query options factory for the current user's API keys on the server.
*
* Uses the same query key as the client-side `listApiKeysOptions` so that data
* fetched during SSR hydrates seamlessly into the client's React Query cache.
*
* @param auth - The Better Auth server instance with the API key plugin.
* @param userId - The signed-in user's ID. Used for cache partitioning.
* @param params - Parameters forwarded to `auth.api.listApiKeys`.
*/
export declare function listApiKeysOptions<TAuth extends ApiKeyAuthServer>(auth: TAuth, userId: string, params: ListApiKeysParams<TAuth>): QueryOptions<Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>, APIError, Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>, readonly ["auth", "user", string | undefined, "apiKey", "list", {
configId?: string | undefined;
organizationId?: string | undefined;
limit?: unknown;
offset?: unknown;
sortBy?: string | undefined;
sortDirection?: "asc" | "desc" | undefined;
} | null], never> & {
queryKey: DataTag<readonly ["auth", "user", string | undefined, "apiKey", "list", {
configId?: string | undefined;
organizationId?: string | undefined;
limit?: unknown;
offset?: unknown;
sortBy?: string | undefined;
sortDirection?: "asc" | "desc" | undefined;
} | null], Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>, APIError>;
};
/**
* Get the current user's API keys from the query cache, calling
* `fetchListApiKeys` under the hood if no cached entry exists.
*
* @param queryClient - The React Query client used for SSR hydration.
* @param auth - The Better Auth server instance with the API key plugin.
* @param userId - The signed-in user's ID, used for cache partitioning.
* @param params - Parameters forwarded to `auth.api.listApiKeys`.
*/
export declare const ensureListApiKeys: <TAuth extends ApiKeyAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: ListApiKeysParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>>;
/**
* Prefetch the current user's API keys into the query cache.
*
* @param queryClient - The React Query client used for SSR hydration.
* @param auth - The Better Auth server instance with the API key plugin.
* @param userId - The signed-in user's ID, used for cache partitioning.
* @param params - Parameters forwarded to `auth.api.listApiKeys`.
*/
export declare const prefetchListApiKeys: <TAuth extends ApiKeyAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: ListApiKeysParams<TAuth>) => Promise<void>;
/**
* Fetch and cache the current user's API keys, resolving with the data or
* throwing on error.
*
* @param queryClient - The React Query client used for SSR hydration.
* @param auth - The Better Auth server instance with the API key plugin.
* @param userId - The signed-in user's ID, used for cache partitioning.
* @param params - Parameters forwarded to `auth.api.listApiKeys`.
*/
export declare const fetchListApiKeys: <TAuth extends ApiKeyAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: ListApiKeysParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["listApiKeys"]>>>;