Queries
useHasPermission
Check organization permissions for the current member.
Organization queries require organizationClient() on your Better Auth client. Queries that depend on a signed-in user wait for session data before calling Better Auth.
Usage
import { useAuth, useHasPermission } from "@better-auth-ui/react"
const { authClient } = useAuth()
const result = useHasPermission(authClient, {
permissions: { organization: ["update"] }
})Client options factory and router-loader helpers
import {
ensureHasPermission,
fetchHasPermission,
hasPermissionOptions,
prefetchHasPermission
} from "@better-auth-ui/react"
const params = {
organizationId: "org_123",
permissions: { organization: ["update"] }
}
const options = hasPermissionOptions(authClient, userId, params)
await ensureHasPermission(queryClient, authClient, userId, params)
await prefetchHasPermission(queryClient, authClient, userId, params)
const permission = await fetchHasPermission(
queryClient,
authClient,
userId,
params
)Notes
useActiveOrganizationtreatsslug: undefinedas the session active organization, a string slug as a URL-selected organization, andslug: nullas intentionally no active organization.- Member, invitation, and permission helpers follow upstream active-organization fallback behavior when an organization id is not provided.
useHasPermissionpreserves Better Auth's flat permission parameter shape.
Server-side prefetching
For server loaders, import from @better-auth-ui/react/server. Server helpers use the Better Auth server endpoint shape: pass the Better Auth server instance, signed-in userId, and request params with the permission payload under body.
import { ensureHasPermission } from "@better-auth-ui/react/server"
import { getRequestHeaders } from "@tanstack/react-start/server"
import { auth } from "@/lib/auth"
await ensureHasPermission(queryClient, auth, userId, {
headers: getRequestHeaders(),
body: {
organizationId: "org_123",
permissions: { organization: ["update"] }
}
})Params
Prop
Type
Last updated on