Authorization
Overview
Evolution of the Auth System
Phase 1: Auth.js with Database Roles (Initial)
┌─────────────────────────────────────────────────────────────────┐
│ PHASE 1: Auth.js + Database Role Columns │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Authentication: Auth.js (Google, Microsoft OAuth) │
│ Session: Drizzle adapter storing sessions in Postgres │
│ │
│ Role Storage: │
│ • tenant_users.role → 'owner' | 'admin' | 'member' │
│ • group_users.role → 'admin' | 'member' │
│ • users.role → 'user' | 'admin' (platform level) │
│ │
│ Permission Checking: │
│ • Hardcoded role checks: if (role === 'admin') { ... } │
│ • No granular permissions │
│ • Role implies all capabilities for that level │
│ │
└─────────────────────────────────────────────────────────────────┘Phase 2: FusionAuth with Permissions Table
Phase 3: Fully Database-Managed Authorization (Current)
Migration Summary
Aspect
Phase 1
Phase 2
Phase 3 (Current)
Deprecated Elements
Lessons Learned
Defense-in-Depth Architecture
Authorization Architecture
Security Model: RLS vs API Enforcement
Two Layers of Defense
Layer
Enforces
Purpose
Why RLS Doesn't Enforce Groups
Security Boundaries
Role Classification System
tenant_id
bypass_rls
Category
Who Sees It
Who Can Use It
Example
Role Scope Types
scope_type
Description
Assignment
bypass_rls Behavior
Database Constraint
Platform Roles (Internal Team)
Super Admin
Platform Admin
Developer
Support
System Roles (Tenant Scope)
Account Owner
Organization Admin
Compliance Manager
HR Administrator
Manager
Employee
Permission System
Permission Naming Convention
Standard Actions
Action
Description
Permission Visibility
Database Schema
Core Auth Tables
auth_permission - Atomic Capabilities
auth_permission - Atomic Capabilitiesauth_role - Permission Groups
auth_role - Permission Groupsauth_role_permission - Role → Permission Mapping
auth_role_permission - Role → Permission Mappingauth_assignment - User → Role in Scope
auth_assignment - User → Role in Scopeauth_permission_cache - Denormalized for RLS Performance
auth_permission_cache - Denormalized for RLS PerformanceRLS Permission Function
RLS Policy Examples
OAuth Scopes (M2M Authentication)
Scope vs Permission
Concept
Granularity
Example
Used By
OAuth Scope Tables
oauth_scope - Versioned Scopes
oauth_scope - Versioned Scopesoauth_scope_permission - Scope → Permission Mapping
oauth_scope_permission - Scope → Permission MappingInternal vs External Scopes
Scope Naming Convention
M2M Client Types
M2M Token Flow
AuthContext Structure
Frontend Permission Structure
UI Permission Guards
PermissionGuard Component
usePermissions Hook
Cache Invalidation
Custom Roles
Example Custom Roles
Best Practices
Related Documentation
Last updated