Supabase Auth Rollout
Intent
Section titled “Intent”Document the current Supabase auth implementation across the emergent apps and the next rollout steps that are already agreed.
Baseline
Section titled “Baseline”- emergent is a self-hosted Supabase app.
auth.users, GoTrue session handling, Supabase auth hooks, and Supabase recovery and invite flows are first-class dependencies. public.personandpublic.person_profileare materialized fromauth.usersrather than maintained as a separate identity system.public.person_role_grantremains the authorization source of truth.- Active grants are projected into
auth.users.raw_app_meta_data.authorization, and frontend, API, and RLS code consume structuredAuthorizationClaimsrather than coarse role arrays. - Project-owned
auth.*helper tables and replacement token flows are out of scope unless Supabase behavior forces a gap.
Shared Frontend Implementation
Section titled “Shared Frontend Implementation”packages/domainowns the cross-app Supabase browser auth primitives: required public env resolution, cached browser client bindings, auth snapshot helpers, access-token loading, and error normalization.packages/uiowns the shared React auth layer:createSupabaseAuthBindings,AuthLoginScreen,AuthResetPasswordRequestScreen,AuthSetPasswordScreen, and the shareduseSupabaseSetPasswordFlowrecovery hook.apps/learner-web,apps/teacher-portal, andapps/admin-consolekeep only app-local theme, access-policy, and route-guard concerns on top of those shared layers.- All three apps now use the same shared provider factory, the same shared login and reset-password request screens, and the same shared
/set-passwordrecovery-completion flow. apps/admin-consolenow includes the shared portal invite UI. It sends Supabase invites for teacher-portal staff roles (teacher,assistant,observer,mentor) plus admin-console roles (organization_admin,platform_admin), lets platform admins choose or manually enter organization scope when they are not pinned to a single organization, and supports offering-scoped teacher-role invites when access needs to be limited below the organization level.apps/learner-webkeeps self-serve signup.apps/teacher-portalandapps/admin-consoleremain invite-only. Their login and reset request routes exist, but they do not expose self-serve account creation.- Password reset emails now redirect back into each app’s public
/set-passwordroute, which restores the Supabase recovery session and completes password changes throughauth.updateUser(...).
Backend And Policy Implementation
Section titled “Backend And Policy Implementation”packages/dbmigrations preserve the Supabase-auth-centered model: auth-hook materialization, authorization claim projection, and claim-aware RLS on mutable sync tables.apps/apiverifies bearer tokens against Supabase, preservesapp_metadata, and builds request claims from the projected authorization structure.apps/apinow exposes an authenticated/workflow/invitespath for the shared portal invite flow. It uses the Supabase admin invite API, supports organization-scoped and offering-scoped teacher-role invites plus organization-admin and platform-admin invites, validates that offering-scoped invites stay attached to the selected organization, and immediately creates the matchingperson_role_grantrow so claim projection can populateraw_app_meta_data.authorization.- Mutation ingress continues to use the Supabase-hosted functions path and forwards claim-enriched auth into the pgxsinkit artifact-mode write path.
- Auth email rendering is handled through the existing send-email hook surface in
apps/api/src/email/templates.tsfor signup, recovery, invite, magic link, and change-email flows.
Implementation Anchors
Section titled “Implementation Anchors”packages/domain: auth contracts and browser auth helperspackages/ui: shared auth providers and screenspackages/db: Supabase auth hook migrations, claim projection, and claim-aware RLSapps/api: Supabase token verification and auth email templatesapps/learner-web: learner signup and learner-specific post-login routingapps/teacher-portal: teacher access-policy checks and invite-only gatingapps/admin-console: admin access-policy checks and invite-only gating
Immediate Next Steps
Section titled “Immediate Next Steps”- Add integration coverage for the default Supabase-backed
/workflow/invitespath so offering-scoped invites are exercised against realpublic.offeringdata and grant projection, not only route-level mocks. - Replace the current claim-derived and manual organization/offering inputs with canonical admin-console catalog pickers once that directory data is available in the portal.
- Revisit pgxsinkit generalization only after the emergent Supabase-first flow is stable and validated.