UNPKG

@better-auth-ui/core

Version:

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

40 lines (39 loc) 3.02 kB
import { DataTag, QueryClient, QueryOptions } from '@tanstack/query-core'; import { APIError } from 'better-auth'; import { OrganizationAuthServer } from '../../../plugins/organization/server/organization-auth-server'; export type HasPermissionData<TAuth extends OrganizationAuthServer = OrganizationAuthServer> = Awaited<ReturnType<TAuth["api"]["hasPermission"]>>; export type HasPermissionParams<TAuth extends OrganizationAuthServer = OrganizationAuthServer> = Parameters<TAuth["api"]["hasPermission"]>[0]; /** * Query options factory for organization permission checks. * * @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 `hasPermissionOptions` for SSR hydration. * @param params - Parameters forwarded to `auth.api.hasPermission`. */ export declare function hasPermissionOptions<TAuth extends OrganizationAuthServer>(auth: TAuth, userId: string, params: HasPermissionParams<TAuth>): QueryOptions<Awaited<ReturnType<TAuth["api"]["hasPermission"]>>, APIError, Awaited<ReturnType<TAuth["api"]["hasPermission"]>>, readonly ["auth", "user", string | undefined, "organization", "permissions", "has", NonNullable<{ permissions: { readonly organization?: ("update" | "delete")[] | undefined; readonly member?: ("update" | "delete" | "create")[] | undefined; readonly invitation?: ("cancel" | "create")[] | undefined; readonly team?: ("update" | "delete" | "create")[] | undefined; readonly ac?: ("update" | "delete" | "create" | "read")[] | undefined; }; } & { organizationId?: string | undefined; }> | null], never> & { queryKey: DataTag<readonly ["auth", "user", string | undefined, "organization", "permissions", "has", NonNullable<{ permissions: { readonly organization?: ("update" | "delete")[] | undefined; readonly member?: ("update" | "delete" | "create")[] | undefined; readonly invitation?: ("cancel" | "create")[] | undefined; readonly team?: ("update" | "delete" | "create")[] | undefined; readonly ac?: ("update" | "delete" | "create" | "read")[] | undefined; }; } & { organizationId?: string | undefined; }> | null], Awaited<ReturnType<TAuth["api"]["hasPermission"]>>, APIError>; }; export declare const ensureHasPermission: <TAuth extends OrganizationAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: HasPermissionParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["hasPermission"]>>>; export declare const prefetchHasPermission: <TAuth extends OrganizationAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: HasPermissionParams<TAuth>) => Promise<void>; export declare const fetchHasPermission: <TAuth extends OrganizationAuthServer>(queryClient: QueryClient, auth: TAuth, userId: string, params: HasPermissionParams<TAuth>) => Promise<Awaited<ReturnType<TAuth["api"]["hasPermission"]>>>;