Skip to content

Platform Administration

Super-admin consoles at /super-admin and /admin, tenant impersonation, plans and feature packs.

4 min read

Overview

Platform Administration is only for Kagami platform operators ("platform super admins"). Salon staff and owners cannot reach it. It gives operators a cross-tenant view for monitoring, support and plan management.

Kagami multi-tenant super admin control plane for organization provisioning and system telemetry

Who counts as a super admin

One definition is shared by the edge proxy and the server helpers (isSuperAdminIdentity in web/src/lib/auth/impersonation.ts, isPlatformSuperAdmin() in web/src/lib/auth/tenant.ts; SALO-2379). A user is a platform super admin if any of these is true:

  • they have a row in the super_admins table,
  • they have a (legacy) memberships.role = 'super_admin' row, or
  • their email is listed in the SUPER_ADMIN_EMAILS environment variable.

The role is always read on the server and never trusted from the client.

Routes

Path What it is Gate
/super-admin Redirects to /admin proxy.ts blocks the whole /super-admin prefix for non-super-admins, then app/super-admin/layout.tsx re-checks
/super-admin/orgs and /super-admin/orgs/[orgId]/... Console: list organisations, drill into an org, create brands, edit a brand, add locations and add staff Same as above
/admin Control plane overview (see below) app/(control)/layout.tsx redirects non-super-admins to /sign-in
/admin/orgs/[orgId] Per-org subscription, feature overrides and playbook pilot Control layout, plus verifySuperAdmin() inside the server actions
/admin/feature-packs Edit plan feature packs, change an org's plan, add or remove feature overrides Control layout
/dashboard/super-admin Platform stats, system health and log viewer (inside the tenant dashboard shell) requireRoleForPage(["super_admin"]); other roles see a permission-denied state
/api/super-admin/system, /api/super-admin/logs System health and PM2 log tail used by the dashboard panels Route handlers check for super admin themselves

Note: the two route handlers under /api/super-admin check memberships.role === 'super_admin' only. A super admin identified solely by the super_admins table or SUPER_ADMIN_EMAILS (without a legacy membership row) would not pass them. This differs from the shared definition above.

Control plane overview (/admin)

Reads across all tenants with the Supabase service-role client. Month-to-date cards: organisations, platform MRR (active subscriptions times plan monthly price), paid revenue, appointments, AI cost (exact, from ai_usage_log), emails (estimated Resend cost) and WhatsApp messages (estimated Meta cost). The table lists up to 200 organisations (newest first) with a subscription-status filter, a health dot, plan, status, revenue, appointments, AI cost, renewal or trial end, and an "Enter as" control. Partial load failures are shown in an alert rather than silently rendering zeros.

Platform stats (/dashboard/super-admin)

Sections: All Time, Growth (last 7 days), Today, This Month and a tenant list, plus the system health and log panels. Figures come from web/src/lib/super-admin/stats.ts.

Impersonation ("Enter as")

A super admin can preview a tenant as a chosen role: owner, brand manager, location manager, front desk or stylist (IMPERSONATABLE_ROLES; super_admin itself is not offered).

  • assumeTenant (org plus role) and assumeRole (role only) set an httpOnly, sameSite=strict cookie, then redirect to /dashboard. exitImpersonation clears both cookies.
  • Every action re-verifies the real identity with isPlatformSuperAdmin(), and the cookie value is only honoured for a verified super admin, so setting the cookie by hand does nothing.
  • An impersonation banner (components/impersonation-banner.tsx) is shown while active.

Role hierarchy and constants

Defined in web/src/lib/auth/types.ts:

Constant Roles included
ALL_ROLES super_admin, org_owner, brand_manager, location_manager, front_desk, stylist
OPS_ROLES super_admin, org_owner, brand_manager, location_manager, front_desk
ADMIN_ROLES super_admin, org_owner, brand_manager, location_manager
MANAGER_ROLES super_admin, org_owner, brand_manager, location_manager (identical to ADMIN_ROLES today)
OWNER_ROLES super_admin, org_owner
SUPER_ADMIN_ONLY super_admin

Server-side helpers in web/src/lib/auth/require-role.ts: requireRole(allowed) (redirects on mismatch), requireAnyAdmin() (ADMIN_ROLES), requireManagerOrAbove() (MANAGER_ROLES) and requireRoleForPage(allowed) (returns null so the page can render a permission-denied state). They resolve the caller's effective role on the server.

Security notes

  • Control-plane and console data use the service-role key, which bypasses RLS on purpose. Keep that code behind the super-admin gates above.
  • Plan limits are enforced for staff and locations: checkPlanLimit() in web/src/lib/saas-billing/index.ts blocks adds when a subscription is lapsed or the trial has expired, or when max_staff / max_locations on the plan is exceeded. It is called from onboarding, location creation and staff invitations.
  • Not found in code, so not documented as features: an IP allowlist for the control plane (the old doc said it was handled at the OCI firewall; that is infrastructure, unverified) and a DPDP export route under the control plane (/api/dpdp/export does not exist). The only export route found is /api/org/export, whose output carries a DPDP handling notice.

Permissions

Capability super_admin
Platform overview and tenant list Yes
Preview any tenant as a chosen role Yes
Create brands, locations and staff for a tenant (/super-admin/orgs) Yes
Change an org's plan, expiry and feature overrides Yes
Edit plan feature packs Yes
View system health and server logs Yes