Headless / Account
Active sessions
Compose sessions with the auth service and your own interface.
13 public parts · 1examples
@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 googleAdds 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 { Sessions } from "@slices.sh/auth/headless"export function Example() { return ( <Sessions.Root> <Sessions.Item> <Sessions.Current>This device</Sessions.Current> <Sessions.ActionTrigger>Sign out device</Sessions.ActionTrigger> <Sessions.ActionDialog> <Sessions.Confirm>Confirm</Sessions.Confirm> <Sessions.Cancel>Cancel</Sessions.Cancel> </Sessions.ActionDialog> </Sessions.Item> <Sessions.Empty>No sessions.</Sessions.Empty> <Sessions.Error /> </Sessions.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.
Sessions.Rootscope
Available gates the section where the backend lists sessions.
Capability: sessions
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
Sessions.Rootfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/root.tsx
Sessions.Availablegate
Available gates the section where the backend lists sessions.
Capability: 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
Sessions.Availablefrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/available.tsx
Sessions.Loadinggate
Loading, Empty, Error (<p role="alert"> with { message }) and Retry for the read.
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
Sessions.Loadingfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/loading.tsx
Sessions.Emptygate
Loading, Empty, Error (<p role="alert"> with { message }) and Retry for the read.
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
Sessions.Emptyfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/empty.tsx
Sessions.Errorcontent · <p>
Loading, Empty, Error (<p role="alert"> with { message }) and Retry for the read.
Props
2 documented props · Native <p> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { 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
Sessions.Errorfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/error.tsx
Sessions.Retryaction · <button>
Loading, Empty, Error (<p role="alert"> with { message }) and Retry for the read.
Props
2 documented props · Native <button> 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
Sessions.Retryfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/retry.tsx
Sessions.Itemcontent · <li>
Item repeats once per session with { browser, os, createdAt, ipAddress }; unknown values are null. Current opens inside this device's row.
Required scope
Sessions.Item provides its own scope.
Props
2 documented props · Native <li> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: {
browser: string | null
os: string | null
createdAt: Date
ipAddress: string | null
/** The address is this machine's (loopback) or none (unspecified), as on a dev server. */
local: 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
Sessions.Itemfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/item.tsx
Sessions.Currentgate
Item repeats once per session with { browser, os, createdAt, ipAddress }; unknown values are null. Current opens inside this device's row.
Required scope
Sessions.Current requires a device row.
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
Sessions.Currentfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/current.tsx
Sessions.ActionDialogcontent
ActionDialog maps the armed state onto render={<AlertDialog />}. ActionTrigger arms it, with { pending, retryAfter }. Confirm ends the session, or every other one outside a row. Cancel disarms. ActionError gets { message }.
Required scope
Sessions.ActionDialog requires Sessions.Root.
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
Sessions.ActionDialogfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/action-dialog.tsx
Sessions.ActionTriggeraction · <button>
ActionDialog maps the armed state onto render={<AlertDialog />}. ActionTrigger arms it, with { pending, retryAfter }. Confirm ends the session, or every other one outside a row. Cancel disarms. ActionError gets { message }.
Required scope
Sessions.ActionTrigger requires Sessions.Root.
Props
2 documented props · Native <button> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { pending: boolean; retryAfter: number }) => 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
Sessions.ActionTriggerfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/action-trigger.tsx
Sessions.Cancelaction · <button>
ActionDialog maps the armed state onto render={<AlertDialog />}. ActionTrigger arms it, with { pending, retryAfter }. Confirm ends the session, or every other one outside a row. Cancel disarms. ActionError gets { message }.
Required scope
Sessions.Cancel requires Sessions.Root.
Props
2 documented props · Native <button> 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
Sessions.Cancelfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/cancel.tsx
Sessions.Confirmaction · <button>
ActionDialog maps the armed state onto render={<AlertDialog />}. ActionTrigger arms it, with { pending, retryAfter }. Confirm ends the session, or every other one outside a row. Cancel disarms. ActionError gets { message }.
Required scope
Sessions.Confirm requires Sessions.Root.
Props
2 documented props · Native <button> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { pending: boolean; retryAfter: number }) => 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
Sessions.Confirmfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/confirm.tsx
Sessions.ActionErrorcontent · <p>
ActionDialog maps the armed state onto render={<AlertDialog />}. ActionTrigger arms it, with { pending, retryAfter }. Confirm ends the session, or every other one outside a row. Cancel disarms. ActionError gets { message }.
Required scope
Sessions.ActionError requires Sessions.Root.
Props
2 documented props · Native <p> attributes supported
| Prop | Type | Default |
|---|---|---|
childrenContent rendered inside this part. | ReactNode | ((state: { 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
Sessions.ActionErrorfrom@slices.sh/auth/headless/sessions
Source: @slices.sh/auth/src/headless/sessions/action-error.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
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.