import { organizationMutationKeys } from "@better-auth-ui/core/plugins" import { mutationOptions, useMutation } from "@tanstack/react-query" import type { BetterFetchError } from "better-auth/react" import type { OrganizationAuthClient } from "../../lib/auth-client" export type CheckSlugParams = Parameters[0] export type CheckSlugOptions = Omit< ReturnType>, "mutationKey" | "mutationFn" > /** * Mutation options factory for checking organization slug availability. * * @param authClient - The Better Auth client. */ export function checkSlugOptions( authClient: TAuthClient ) { const mutationKey = organizationMutationKeys.checkSlug const mutationFn = (params: CheckSlugParams) => authClient.organization.checkSlug({ ...params, fetchOptions: { ...params?.fetchOptions, throw: true } }) return mutationOptions< Awaited>, BetterFetchError, Parameters[0] >({ mutationKey, mutationFn }) } /** * Create a mutation for checking whether an organization slug is available. * * @param authClient - The Better Auth client with the organization plugin. * @param options - React Query options forwarded to `useMutation`. */ export function useCheckSlug( authClient: TAuthClient, options?: CheckSlugOptions ) { return useMutation({ ...checkSlugOptions(authClient), ...options }) }