Supabase Auth with JWT cookies, RLS-enforced tenant isolation, and a four-tier role hierarchy

Auth & Multi-Tenancy

Supabase Auth with JWT cookies, RLS-enforced tenant isolation, and a four-tier role hierarchy.

Authentication Flow
User Login
Supabase Auth
JWT + Cookie
Middleware
getUser()
Profile +
Org Lookup
SessionContext
userId, orgId, role
RLS Filters
by org_id

Three Supabase Client Types

ClientUsed ByRLS
createBrowserClient()React componentsEnforced
createSupabaseServer()API routes, server componentsEnforced
supabaseAdmin()Webhooks, migrations onlyBypassed

Role Hierarchy

RoleCan Do
OwnerEverything + delete org + manage billing
AdminEverything + manage team members
MemberCreate, edit, publish documents
ViewerRead-only access to all documents
Defense in depth: Auth is checked at THREE layers. (1) Middleware validates JWT and blocks unauthenticated requests. (2) API routes call requireSession() and optionally requireRole(). (3) PostgreSQL RLS policies filter every query by org_id. Even if layers 1 and 2 fail, RLS prevents data leaks.

Ready to create AI-powered proposals?

Start Free