UNPKG

@better-auth-ui/core

Version:

Authentication components and data utilities for [Better Auth](https://better-auth.com), available for React and Solid.

43 lines (42 loc) 2.3 kB
/** * Hierarchical query key factory for every Better Auth query managed by * this library. * * Keys are nested — higher-level keys are valid prefixes of their * descendants — so a single call can invalidate a whole subtree: * * ```ts * queryClient.invalidateQueries({ queryKey: authQueryKeys.all }) * queryClient.invalidateQueries({ queryKey: authQueryKeys.user(userId) }) * queryClient.invalidateQueries({ queryKey: authQueryKeys.session }) * ``` * * This factory lives in `@better-auth-ui/core` so it can be shared across * framework packages (`@better-auth-ui/react`, a future `/solid` package, * etc.) and across client- and server-side query variants — the cache * entries line up regardless of which query options factory produced them. * * Plugin-specific query keys live alongside their plugin (e.g. * `apiKeyQueryKeys`, `organizationQueryKeys`, `passkeyQueryKeys`, * `multiSessionQueryKeys`) and chain off `authQueryKeys.user(userId)` so * everything still sits under the shared `["auth", "user", userId, ...]` * subtree. * * For mutation keys, see `authMutationKeys` in `./auth-mutation-keys`. */ export declare const authQueryKeys: { /** Root key for every Better Auth query. */ readonly all: readonly ["auth"]; /** Key for the current `getSession` query. */ readonly session: readonly ["auth", "getSession"]; /** Prefix for every per-user query. */ readonly users: () => readonly ["auth", "user"]; /** Prefix for every query scoped to a specific user. */ readonly user: (userId?: string) => readonly ["auth", "user", string | undefined]; /** Key for `accountInfo` for the given user. */ readonly accountInfo: <TQuery = undefined>(userId?: string, query?: TQuery) => readonly ["auth", "user", string | undefined, "accountInfo", NonNullable<TQuery> | null]; /** Key for `listAccounts` for the given user. */ readonly listAccounts: <TQuery = undefined>(userId?: string, query?: TQuery) => readonly ["auth", "user", string | undefined, "listAccounts", NonNullable<TQuery> | null]; /** Key for `listSessions` for the given user. */ readonly listSessions: <TQuery = undefined>(userId?: string, query?: TQuery) => readonly ["auth", "user", string | undefined, "listSessions", NonNullable<TQuery> | null]; };