Skip to content

Instantly share code, notes, and snippets.

@mikeni
mikeni / Dynamic Multi-Tenant RBAC with Route Authorization.sql
Created June 18, 2025 09:50 — forked from ThingEngineer/Dynamic Multi-Tenant RBAC with Route Authorization.sql
Dynamic multi-tenant SQL-based RBAC with JWT enhancement, route authorization, and permission management using Supabase.
-- Role-Based Access Control (RBAC)
-- With live propagation of roles to JWT token in a multi-tenant application using Supabase refreshSession and custom_access_token_hook
-- A method of restricting table and route access to authorized users based on their role or permission level.
-- This SQL implements a dynamic, multi-tenant role-based access control (RBAC) system with route authorization. It includes:
-- A custom access token hook that enriches JWT claims with role and company data.
-- Functions to authorize actions, check route access, and retrieve authorized routes based on user roles.