@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
25 lines (23 loc) • 764 B
JavaScript
import { checkAccess } from "./visibility.js";
import { useCurrentUser } from "../auth/isomorphic.js";
//#region src/route/audience.tsx
/**
* Renders `children` to the visitors a rule admits, and `fallback` to the rest.
*
* Use it to hide parts of the tree. The UI for visibility is accessible by the
* builder in Studio.
*
* Requires the root route to resolve {@link getSoftrContext}.
*
* @example
* const membersOnly = defineVisibility({ userGroupTypes: ["LOGGED_IN_USERS"] })
*
* <Audience visibility={membersOnly} fallback={<Upgrade />}>
* <DangerZone />
* </Audience>
*/
function Audience({ visibility, children, fallback = null }) {
return checkAccess(visibility, { user: useCurrentUser() }).ok ? children : fallback;
}
//#endregion
export { Audience };