Browse documentation

People

What this is for

A person is a human user — the public.people row bound to a Supabase auth user. Every signed-in session resolves to exactly one person; that row carries the account placement, role, and status that gate everything the user can see and do. Watchers, messages, notification recipients, and pipeline "who did this" all reference people.id.

Why it exists

You need a single identity table that works across accounts and integrates with Supabase Auth.

Why it exists (5-whys):

  1. Supabase Auth proves who signed in; the platform needs who they are to each account — role, app membership, display identity.
  2. auth_uid + account_id + role_id on one row collapses the principal join: person → role → account → accessible accounts must be resolvable in one table read per request, not a multi-hop lookup.
  3. email unique + auth_uid nullable means identity precedes authentication — invites create the person row before auth exists (pending invites are people rows carrying data.invite_token, per invites.ts).
  4. People are typed (type_id) because person records are domain-shaped too — customer vs staff vs agent personas.
  5. Root: the principal is the unit every security decision flows through — people fuses auth identity, account membership, and role into the row current_actor_id and every RLS policy resolve first. (confirmed 2026-11-13)

Fields and settings

ColumnNotes
auth_uidUNIQUE — the Supabase auth.users.id. NULL on invite stubs (person created before they register).
emailUNIQUE, required. Login + invite identity.
full_namerequired display name.
account_idrequired — the account the person is placed in. Falsy account_id = "unplaced": the router forces /register?resume=1 until placement completes.
role_idFK → roles. The person's role slug drives app gating and record permissions.
statusdefault 'active'. 'pending' users are gated to the pending-approval page by the router.
type_idrequired — people are typed records like everything else.
datajsonb — non-system fields per the person type's design_schema.
avatar_url, phone, is_activeProfile/lifecycle flags.

Downstream effects

  • useAuth().user (@core/contexts/AuthContext) is derived from this row + role join: roles: string[], account_id, is_system_admin, status.
  • The registration lifecycle: register → (email confirm) → person row with account_id unset = unplaced → /register?resume=1 finishes placement → status: 'pending' requires approval → active.
  • handle_new_auth_user grants system_admin only when people is empty — the first registrant claims the instance (see Security checklist).
  • people.role comes back from Supabase as object or array depending on the join — normalize before reading .slug.

Minimal configuration

People rows are created by registration/invites, not by hand — but a valid person requires: email, full_name, account_id, role_id, type_id (the person type), status: 'active'.

Full configuration

Adds avatar_url, phone, data (type-defined fields), app_id (which app created them), is_active.

Example

An invite flow creates a person stub (auth_uid: null, status: 'pending', account_id + role_id set by the invite's config); when the invitee registers with that email, auth_uid binds and they land already placed — skipping the unplaced dance entirely.

Core files

  • .framework/migrations/001_core_schema.sql — table + constraints
  • .framework/functions/auth.ts — session → person + role resolution
  • .framework/functions/invites.ts — invite stubs and placement config
  • .framework/src/contexts/AuthContext.tsx — client useAuth shape
  • .framework/src/pages/auth/RegisterPage.tsx — placement/resume flow

Agent notes

  • Never INSERT a person as a substitute for registration — auth_uid binding and account placement happen through auth/invite paths.
  • status: 'pending' + truthy account_id → pending-approval gate; falsy account_id → resume-registration routing. Different fixes.
  • person_id is the FK used by watchers, messages, notifications, item_progress — it's people.id, never auth_uid.
  • onAuthStateChange callbacks must never await Supabase calls — auth-js awaits listeners inside initializePromise, so fetchUserContext → apiFetch → getAuthHeaders → getSession deadlocks until SESSION_TIMEOUT_MS (15 s of spinner on every expired-session visit). Defer the work (setTimeout) inside the callback.

Framework documentation — Verified November 2, 2026 · source revision bc4b9e9.

Was this page helpful? Ask a question · Report a documentation problem