Headless / Organizations
Switch or create a workspace
Search accessible organizations and switch the active workspace.
29 public parts · 3examples
@slices.sh/auth/headlessView as Markdown ↗Your design. Our behavior.
Explore the tree to see what each part controls. Gates reveal the relevant state; roots outline their scope.
User.Root · Scope
Installation
Choose what your component needs. Run these commands in an initialized Next.js app.
Before you start
The steps below run in a Next.js app with shadcn set up (it has a components.json). In an existing Next.js app, such as one from create-next-app, set shadcn up first:
npx shadcn@latest init -t next -b base -p novaOr start fresh: the slices CLI creates the app and sets it up.
npx slices.sh installInstall the service registry
Adds services/index.ts, which import "@/services" loads. A provider setup writes the same file, so skip this if your app has one.
npx add servicesInstall the headless library
npmAdd the React parts to your app, then compose them with your own elements.
npm install @slices.sh/auth@^0.1.10Import from @slices.sh/auth/headless.
Install the service
Connect the parts to a provider. Skip this step if this service is already configured in your app.
npx add auth.betterauth --auth-methods google --organizationsAdds service configuration and API routes to your app, with the provider dependencies. For a headless composition, add import "@/services" after "use client".
The slices CLI installs the service and provisions its required resources in one command.
Set BETTER_AUTH_URL to your app origin. Memory is for local development; use a persistent database for deployment. Neon and Supabase also require the migration script printed by the installer.
Provider setup notes
- BETTER_AUTH_SECRET signs every session and is generated into .env.local while this installs (32 random bytes, base64, nothing leaves the machine). Changing it signs everyone out; in production set the same one on every instance.
- The public origin (OAuth callbacks, the passkey domain) is the one each request comes to in development, and the deployment's own on Vercel. Elsewhere, or behind a proxy or a custom domain, set BETTER_AUTH_URL, such as https://acme.com.
Start small
Parts bring the behavior. Use their default elements, or supply your own with render.
"use client"import "@/services"import { User, Organization } from "@slices.sh/auth/headless"export function Example() { return ( <User.Root> <Organization.Switcher.Options> <Organization.Switcher.Input aria-label="Find a workspace" /> <Organization.Switcher.List> <Organization.Switcher.Item /> </Organization.Switcher.List> <Organization.Switcher.Empty> No matches. </Organization.Switcher.Empty> </Organization.Switcher.Options> </User.Root> )}Requires an authenticated account. Organization controls also require organizations and the appropriate role.
API reference
Every public part used by this experience is listed below. Gates render children without adding an element. Element parts accept native element props and render; function children receive the state declared in their props. Scopes provide context rather than a visual element.
Organization.Rolecontent
For the organization in scope. Name is text. Logo is <img alt=""> and nothing without a logo. Role gets { role }, the person's role in it. Manage is the host's link to the active organization's settings.
Required scope
Organization.Role requires Organization.Item or Organization.Active.
Props
2 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { role: MemberRole | null }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Rolefrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/role.tsx
Organization.Managecontent · <a>
The host owns where settings for the currently active organization live.
Props
2 documented props · Native <a> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Managefrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/manage.tsx
Organization.Itemaction · <button>
Item is a <button> repeated once per organization with { active, pending }; clicking makes it active. Personal switches to the personal account. Active renders its children with the active organization in scope, and nothing on the personal account; None is its mirror, once the answer is in. Switcher holds the searchable list: Switcher.Surface maps onto a Popover or a Sheet, Switcher.Options, Input, List, Item, Empty and Error search and list, and Switcher.Shortcuts binds keys to switch.
Capability: organizations
Props
2 documented props · Native <button> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { active: boolean; pending: boolean }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Itemfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/item.tsx
Organization.Personalaction · <button>
Item is a <button> repeated once per organization with { active, pending }; clicking makes it active. Personal switches to the personal account. Active renders its children with the active organization in scope, and nothing on the personal account; None is its mirror, once the answer is in. Switcher holds the searchable list: Switcher.Surface maps onto a Popover or a Sheet, Switcher.Options, Input, List, Item, Empty and Error search and list, and Switcher.Shortcuts binds keys to switch.
Capability: organizations
Props
2 documented props · Native <button> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { active: boolean }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Personalfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/personal.tsx
Organization.Activegate
Item is a <button> repeated once per organization with { active, pending }; clicking makes it active. Personal switches to the personal account. Active renders its children with the active organization in scope, and nothing on the personal account; None is its mirror, once the answer is in. Switcher holds the searchable list: Switcher.Surface maps onto a Popover or a Sheet, Switcher.Options, Input, List, Item, Empty and Error search and list, and Switcher.Shortcuts binds keys to switch.
Capability: organizations
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Activefrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/active.tsx
Organization.Nonegate
Item is a <button> repeated once per organization with { active, pending }; clicking makes it active. Personal switches to the personal account. Active renders its children with the active organization in scope, and nothing on the personal account; None is its mirror, once the answer is in. Switcher holds the searchable list: Switcher.Surface maps onto a Popover or a Sheet, Switcher.Options, Input, List, Item, Empty and Error search and list, and Switcher.Shortcuts binds keys to switch.
Capability: organizations
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Nonefrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/none.tsx
Organization.Namecontent
For the organization in scope. Name is text. Logo is <img alt=""> and nothing without a logo. Role gets { role }, the person's role in it. Manage is the host's link to the active organization's settings.
Required scope
Organization.Name must be inside <Organization.Item> or <Organization.Active>.
Props
2 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Namefrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/name.tsx
Organization.Logocontent · <img>
For the organization in scope. Name is text. Logo is <img alt=""> and nothing without a logo. Role gets { role }, the person's role in it. Manage is the host's link to the active organization's settings.
Required scope
Organization.Logo must be inside <Organization.Item> or <Organization.Active>.
Props
2 documented props · Native <img> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Logofrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/logo.tsx
Organization.Loadinggate
Loading covers the first load only. Empty opens when the person belongs to none. Error gets { code, message }.
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Loadingfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/loading.tsx
Organization.Emptygate
Loading covers the first load only. Empty opens when the person belongs to none. Error gets { code, message }.
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Emptyfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/empty.tsx
Organization.Errorgate
Loading covers the first load only. Empty opens when the person belongs to none. Error gets { code, message }.
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { code: AuthErrorCode; message: string }) => ReactNode) | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Errorfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/error.tsx
Organization.Switcher.Shortcutsscope
Organization.Switcher.Shortcuts provides state to the parts inside it.
Props
2 documented props
| Prop | Type | Default |
|---|---|---|
enabled | boolean | false |
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Switcher.Shortcutsfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/switch-shortcuts.tsx
Organization.Switcher.Surfacecontent
Organization.Switcher.Surface renders content from its current scope.
Props
2 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Switcher.Surfacefrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/switcher-surface.tsx
Organization.Switcher.Optionsscope
Organization.Switcher.Options provides state to the parts inside it.
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Switcher.Optionsfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/search-root.tsx
Organization.Switcher.Inputinput · <input>
Organization.Switcher.Input renders a input element.
Props
2 documented props · Native <input> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Switcher.Inputfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/search-input.tsx
Organization.Switcher.Listcontent · <div>
Organization.Switcher.List renders a div element.
Props
2 documented props · Native <div> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Switcher.Listfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/search-list.tsx
Organization.Switcher.Itemcontent · <div>
Organization.Switcher.Item renders a div element.
Required scope
Organization.Switcher.Item must be inside <Organization.Switcher.Options>.
Props
2 documented props · Native <div> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { active: boolean; pending: boolean }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Switcher.Itemfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/search-item.tsx
Organization.Switcher.Emptygate
Organization.Switcher.Empty conditionally renders its children.
Required scope
Organization.Switcher.Empty must be inside <Organization.Switcher.Options>.
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Switcher.Emptyfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/search-empty.tsx
Organization.Switcher.Errorgate
Organization.Switcher.Error conditionally renders its children.
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { code: AuthErrorCode; message: string }) => ReactNode) | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Switcher.Errorfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/search-error.tsx
Organization.Create.Dialogcontent
Organization.Create.Dialog renders content from its current scope.
Props
2 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Create.Dialogfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/create-dialog.tsx
Organization.Create.Triggeraction · <button>
Organization.Create.Trigger renders a button element.
Props
2 documented props · Native <button> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { query: string }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Create.Triggerfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/create-trigger.tsx
Organization.Create.Formaction · <form>
Organization.Create.Form renders a form element.
Props
2 documented props · Native <form> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { pending: boolean }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Create.Formfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/create-form.tsx
Organization.Create.Labelcontent · <label>
Organization.Create.Label renders a label element.
Required scope
Organization.Create.Label must be inside <Organization.Create.Form>.
Props
2 documented props · Native <label> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Create.Labelfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/create-label.tsx
Organization.Create.Nameinput · <input>
Organization.Create.Name renders a input element.
Required scope
Organization.Create.Name must be inside <Organization.Create.Form>.
Props
2 documented props · Native <input> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { invalid: boolean }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Create.Namefrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/create-name.tsx
Organization.Create.Submitaction · <button>
Organization.Create.Submit renders a button element.
Required scope
Organization.Create.Submit must be inside <Organization.Create.Form>.
Props
2 documented props · Native <button> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { pending: boolean }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Create.Submitfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/create-submit.tsx
Organization.Create.Errorcontent · <div>
Organization.Create.Error renders a div element.
Props
2 documented props · Native <div> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { code: AuthErrorCode; message: string }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Organization.Create.Errorfrom@slices.sh/auth/headless/organization
Source: @slices.sh/auth/src/headless/organization/create-error.tsx
Principals.Knowngate
Known renders once the session and the organizations are known; nothing for a visitor or a backend without sessions.
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Principals.Knownfrom@slices.sh/auth/headless/principals
Source: @slices.sh/auth/src/headless/principals/known.tsx
Principals.PersonalOptioncontent · <option>
PersonalOption is an <option> for the viewer themselves, its value locked to their principal, with { name }. OrganizationOption repeats an <option> per organization the viewer belongs to, its name as default content, and renders nothing without organizations.
Capability: organizations
Props
2 documented props · Native <option> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { name: string | null }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Principals.PersonalOptionfrom@slices.sh/auth/headless/principals
Source: @slices.sh/auth/src/headless/principals/personal-option.tsx
Principals.OrganizationOptioncontent · <option>
PersonalOption is an <option> for the viewer themselves, its value locked to their principal, with { name }. OrganizationOption repeats an <option> per organization the viewer belongs to, its name as default content, and renders nothing without organizations.
Capability: organizations
Props
2 documented props · Native <option> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { name: string }) => ReactNode) | — |
renderReplace the default element with your own while retaining the part’s behavior and accessibility. | ReactElement | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
Principals.OrganizationOptionfrom@slices.sh/auth/headless/principals
Source: @slices.sh/auth/src/headless/principals/organization-option.tsx
User.Rootscope
Says which auth the User parts below read, and whether they may do without it. The parts need no root: left out, they read the nearest auth root's config, or "default", and render nothing without auth. `<User.Root enabled="optional">` is for the one who wants that said in the code.
Props
3 documented props
| Prop | Type | Default |
|---|---|---|
configThe auth config, a slug from the registry ( | string | — |
enabledLeft out or | Enabled | — |
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
User.Rootfrom@slices.sh/auth/headless/userUser.Rootfrom@slices.sh/auth/headless/passkeysUser.Rootfrom@slices.sh/auth/headless/two-factor
Source: @slices.sh/auth/src/headless/user/root.tsx
User.SignedIngate
SignedIn and SignedOut open once the session has answered, so nobody flashes signed out. Loading covers the first load only. SessionExpired opens when the session on screen has run out while its name and picture are still shown. ReadError is <p role="alert"> with { message } when the session could not be read, and Retry reads it again.
Props
1 documented props
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | — |
Required props are marked. A dash means no explicit default is declared in this component.
Alternate public imports
User.SignedInfrom@slices.sh/auth/headless/userUser.SignedInfrom@slices.sh/auth/headless/passkeysUser.SignedInfrom@slices.sh/auth/headless/two-factor
Source: @slices.sh/auth/src/headless/user/signed-in.tsx
When something is missing
- No service configuration
- Install the auth setup below and import "@/services". Required service roots report missing setup; gates do not replace that configuration.
- Missing capability or parent scope
- Follow each part’s context requirements and the example composition. Capability-aware controls hide when the provider cannot perform their action.