{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shell-session-boundary",
  "title": "Session boundary",
  "description": "Shows loading, an error, the introduction or the protected page depending on the session's own state, and turns away the wrong audience.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0"
  ],
  "registryDependencies": [
    "@registrystack/lib-content-provider",
    "@registrystack/shell-branding",
    "@registrystack/shell-content",
    "@registrystack/shell-error-panel",
    "@registrystack/shell-loading",
    "@registrystack/shell-page-heading",
    "@registrystack/shell-sign-out"
  ],
  "files": [
    {
      "path": "shell/session-boundary.tsx",
      "content": "import type { ReactNode } from \"react\";\nimport {\n  AuthorityBoundary,\n  useSession,\n} from \"@registrystack/app-runtime/react\";\nimport type { AuthenticatedSession } from \"@registrystack/app-runtime\";\nimport { ModelMessages } from \"@/blocks/lib/content-provider\";\nimport { useBranding } from \"@/blocks/shell/branding\";\nimport { ErrorPanel } from \"@/blocks/shell/error-panel\";\nimport { Loading } from \"@/blocks/shell/loading\";\nimport { PageHeading } from \"@/blocks/shell/page-heading\";\nimport { SignOut } from \"@/blocks/shell/sign-out\";\nimport { useShellContent } from \"@/blocks/shell/shell-content\";\n\nexport function SessionBoundary({\n  audience,\n  children,\n  introduction,\n}: {\n  audience: \"staff\" | \"service\";\n  children: ReactNode;\n  introduction: ReactNode;\n}) {\n  const session = useSession();\n  if (session.isPending) return <Loading />;\n  // A failed background poll keeps the last session and the page it holds; only\n  // a first read that failed has nothing to show. A session the host ended\n  // arrives as signed-out data, not as an error.\n  if (session.error && !session.data)\n    return (\n      <ErrorPanel error={session.error} retry={() => void session.refetch()} />\n    );\n  if (!session.data?.authenticated) return <>{introduction}</>;\n  if (\n    (audience === \"staff\" && session.data.holder) ||\n    (audience === \"service\" && !session.data.holder)\n  )\n    return <WrongAudience session={session.data} />;\n  return (\n    <AuthorityBoundary key={session.data.scope} session={session.data}>\n      <ModelMessages>{children}</ModelMessages>\n    </AuthorityBoundary>\n  );\n}\n\n/**\n * What a session sees when it authenticated for the other audience: a link\n * to its own service instead of the page it asked for. The page carries the\n * accent of the UI model its session reads, so it looks like the service it\n * points to.\n */\nexport function WrongAudience({ session }: { session: AuthenticatedSession }) {\n  return (\n    <AuthorityBoundary key={session.scope} session={session}>\n      <WrongAudiencePage session={session} />\n    </AuthorityBoundary>\n  );\n}\n\nfunction WrongAudiencePage({ session }: { session: AuthenticatedSession }) {\n  const c = useShellContent();\n  useBranding();\n  return (\n    <main className=\"public-content\">\n      <PageHeading title={c.unavailable} description={c.unavailableBody} />\n      <a\n        className=\"text-link\"\n        href={session.holder ? \"/service/\" : \"/staff/\"}\n      >\n        {session.holder ? c.serviceName : c.staffName}\n      </a>\n      <SignOut />\n    </main>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/shell/session-boundary.tsx"
    }
  ],
  "type": "registry:block"
}