Systems

How portals link

Shared Supabase, packages, Ziteox Account handoff, memberships, and cross-app tokens.

How portals link

Purpose

Admin and client portals are separate hosts and sessions, but they share one platform monorepo, one Supabase project (layered schemas), shared @ziteox/* packages, and Ziteox Account for sign-in. There is no silent cross-portal SSO (parent-domain cookie rejected).

Current state

LinkStatus
Shared monorepo (ziteox-platform / portal checkout)Live — ziteox-admin, ziteox-client, ziteox-auth, packages
Shared Supabase + schema routingLive in code
Account handoff (PKCE one-time codes)In progress — coded; production gated
core.apps / memberships / invites / connectionsIn migrations — apply/go-live gated with Account
Forge Core admin token UINot built on the portal yet (Core API exists locally)

Shared database

  • One Supabase project for admin and client (same NEXT_PUBLIC_SUPABASE_URL pattern in both apps’ env examples).
  • Layered Postgres schemas mapped in portal: packages/supabase-routing — TABLE_SCHEMA + wrapSupabaseSchemaRouting. Layers include core, projects, billing, infra, support, outreach, inbound, hosting, email, partner, finance, zix.
  • Apps re-export / wrap clients so .from("organizations") hits core.organizations, .from("secrets") hits infra.secrets, etc. Client: portal: ziteox-client/src/lib/supabase-schema-routing.ts.
  • Migrations: both portal: ziteox-admin/supabase/migrations/ and portal: ziteox-client/supabase/migrations/; monorepo README treats client supabase folder as the CLI sync home.

Shared packages

From portal: packages/README.md:

PackageRole
@ziteox/authHandoff, roles, ceiling, AAL, sites, invite verify, agent identity
@ziteox/supabase-routingSchema map + client wrap
@ziteox/supabase-utilsAnon / service-role factories
@ziteox/audit-coreShared audit writer
@ziteox/storageBunny Storage helpers
@ziteox/dnsCloudflare DNS helpers
@ziteox/domain-utilsDomain normalize/validate

@ziteox/ui comes from Forge (GitHub Packages); admin consumes it today.

Ziteox Account sign-in + handoff

Design rule (portal: docs/auth-shared-layer-plan-2026-10-29.md): sign-in on admin must not auto-sign into client (or vice versa). Each portal gets a host-only cookie after explicit handoff.

Flow (both portals):

  1. User hits portal /auth/start (optional return_to).
  2. Portal stores PKCE verifier + state in a short-lived handoff cookie; redirects to Account (getAuthAppOrigin() → default https://auth.ziteox.com).
  3. User signs in / picks account on Account; Account issues a one-time code (core.auth_handoff_codes).
  4. Portal /auth/handoff exchanges code via POST Account /api/handoff/token (with site client_secret); sets portal session cookie.

Code pointers:

PiecePath
Admin start / handoffportal: ziteox-admin/src/app/auth/start/route.ts, …/handoff/route.ts, …/lib/auth-handoff.ts
Client start / handoffportal: ziteox-client/src/app/auth/start/route.ts, …/handoff/route.ts, …/lib/auth-handoff.ts
Account token APIportal: ziteox-auth/src/app/api/handoff/token/route.ts
Shared handoff + registryportal: packages/auth/src/handoff/
Cookie policyportal: packages/auth/src/cookie-options.ts (host-only; no parent domain)
Handoff codes migrationportal: ziteox-admin/supabase/migrations/20261029210000_auth_handoff_codes.sql

Site registration (origins, callbacks, staff/2FA policy): portal: ziteox-admin/supabase/migrations/20261031200000_app_site_registration.sql and productionHandoffSites() in portal: packages/auth/src/handoff/registry.ts.

App keyOrigins / callback (seed)Staff2FA
adminhttps://admin.ziteox.com → /auth/handoffrequiredrequired; max age 43200s (12h)
clienthttps://client.ziteox.com → /auth/handoffnono

Memberships, invites, connections

TableRole
core.appsCatalog: admin, client, rail (+ handoff policy columns)
core.app_rolesRanked roles per app
core.app_membershipsUser ↔ app (± org) grants; admin org must be null
core.app_invitesEmail invites into an app role
core.app_connectionsPer-user first/last handoff use per app

Migration: portal: ziteox-admin/supabase/migrations/20261029220000_app_role_registry.sql, …/20261101000000_app_connections.sql.

TS registry / ceiling: portal: packages/auth/src/roles/registry.ts, ceiling.ts. Invite accept surfaces on Account (/invite/accept).

Cross-app APIs / service tokens

MechanismWhat
MCP bearer tokensPrefix zxmcp_; stored hashed in core.mcp_service_tokens (expires_at required). Issued from admin (portal: ziteox-admin/src/lib/mcp-service-tokens.ts); used on portal: ziteox-admin/src/app/api/mcp/route.ts. Shared identity helpers: portal: packages/auth/src/identity/.
Device authorizationAccount /api/device/* + /device UI for agent pairing (RFC 8628).
Site secretsPer-portal handoff client secrets (env names such as ZITEOX_SITE_SECRET on admin/client; Account-side site secret env names documented in Account Cloudflare/env examples) — values never in Forge docs.
Schema routingNot a network API — shared PostgREST access with schema wrap.

There is no shared browser session across admin and client. Cross-app automation goes through Account handoff, MCP tokens, or service-role server paths — not a parent-domain cookie.

Domains (defaults in code)

SurfaceDefault origin
Accounthttps://auth.ziteox.com
Adminhttps://admin.ziteox.com
Clienthttps://client.ziteox.com
Partner (related)https://partner.ziteox.com

From portal: packages/auth/src/sites.ts. Whether DNS/Vercel/Worker production currently points there: (unverified) from this docs pass alone.

Forge Core integration (decided 2026-11-01)

How admin (team-member Account side) will talk to Forge Core. The portal side is not built yet.

  • Core project tokens (zxcore_) are per project — never one member token spanning projects.
  • Admin registers projects and obtains tokens on a member’s behalf with Ed25519 admin assertions (member_id claim).
  • Admin shows one screen listing a member’s tokens across all their projects via Core GET /v1/admin/members/:memberId/tokens (local-only today).
  • Spec: Admin portal integration.

Sources

  • portal: README.md, packages/README.md
  • portal: packages/auth/ (sites.ts, cookie-options.ts, handoff/, roles/, identity/)
  • portal: packages/supabase-routing/src/index.ts
  • portal: ziteox-admin/src/app/auth/, ziteox-client/src/app/auth/
  • portal: ziteox-auth/src/app/api/handoff/token/route.ts
  • portal: ziteox-admin/supabase/migrations/20261029210000_auth_handoff_codes.sql
  • portal: ziteox-admin/supabase/migrations/20261029220000_app_role_registry.sql
  • portal: ziteox-admin/supabase/migrations/20261031200000_app_site_registration.sql
  • portal: ziteox-admin/supabase/migrations/20261101000000_app_connections.sql
  • portal: ziteox-admin/supabase/migrations/20261012160000_mcp_service_token_expires_at.sql
  • portal: docs/auth-shared-layer-plan-2026-10-29.md
  • Forge: docs/core/admin-portal-integration.mdx