Mutations
useIsUsernameAvailable
Check whether a username is free to claim.
Modeled as a mutation (not a query) because callers typically trigger the check on user action — a debounced input or form submit — rather than on mount.
data is typed as { available: boolean; message: string | null }.
Usage
import {
type UsernameAuthClient,
useAuth,
useIsUsernameAvailable
} from "@better-auth-ui/react"
const { authClient } = useAuth()
const { mutateAsync: checkUsername, data } = useIsUsernameAvailable(
authClient as UsernameAuthClient
)
const result = await checkUsername({ username: "alice" })
// result.available -> booleanuseIsUsernameAvailable requires the Better Auth username plugin. Cast authClient to UsernameAuthClient so TypeScript picks up the plugin-extended method signature.
Options factory
import { isUsernameAvailableOptions } from "@better-auth-ui/react"
import { useMutation } from "@tanstack/react-query"
const { mutate } = useMutation(isUsernameAvailableOptions(authClient))Params
Prop
Type
Last updated on