Queries
useActiveOrganization
Read the active organization from the session or a URL slug.
Usage
import { useActiveOrganization } from "@better-auth-ui/solid"
const result = useActiveOrganization(authClient)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 { activeOrganizationOptions } from "@better-auth-ui/solid"
import { createQuery } from "@tanstack/solid-query"
const query = createQuery(() =>
activeOrganizationOptions(authClient, userId)
)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 {
ensureActiveOrganization,
fetchActiveOrganization,
prefetchActiveOrganization
} from "@better-auth-ui/solid"
await ensureActiveOrganization(queryClient, authClient, userId, { query: { organizationId: "org_123" } })
await prefetchActiveOrganization(queryClient, authClient, userId, { query: { organizationId: "org_123" } })
const organization = await fetchActiveOrganization(queryClient, authClient, userId, { query: { organizationId: "org_123" } })Params
Prop
Type
Last updated on