Queries
useHasPermission
Check organization permissions for the current member.
Usage
import { useHasPermission } from "@better-auth-ui/solid"
const result = useHasPermission(authClient, {
permissions: { organization: ["update"] }
})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.
Options factory
import { hasPermissionOptions } from "@better-auth-ui/solid"
import { createQuery } from "@tanstack/solid-query"
const params = {
organizationId: "org_123",
permissions: { organization: ["update"] }
}
const query = createQuery(() =>
hasPermissionOptions(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 Solid route loaders, import the router-loader helpers from @better-auth-ui/solid. These helpers use the Solid client-shaped authClient/userId signature so they hydrate into the same cache keys as the component hook. True server-auth Organization helpers are not currently exported from @better-auth-ui/solid/server; use the session server helper first when your route needs request-header authentication.
import {
ensureHasPermission,
fetchHasPermission,
prefetchHasPermission
} from "@better-auth-ui/solid"
await ensureHasPermission(queryClient, authClient, userId, {
organizationId: "org_123",
permissions: { organization: ["update"] }
})
await prefetchHasPermission(queryClient, authClient, userId, {
organizationId: "org_123",
permissions: { organization: ["update"] }
})
const permission = await fetchHasPermission(queryClient, authClient, userId, {
organizationId: "org_123",
permissions: { organization: ["update"] }
})Params
Prop
Type
Last updated on