BETTER-AUTH. UI
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

  • useActiveOrganization treats slug: undefined as the session active organization, a string slug as a URL-selected organization, and slug: null as intentionally no active organization.
  • Member, invitation, and permission helpers follow upstream active-organization fallback behavior when an organization id is not provided.
  • useHasPermission preserves 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

On this page