Files
Stirling-PDF/frontend/shared/auth/roles.ts
T
James Brunton 1816bad1ba Unified auth for portal and editor (#6725)
# Description of Changes
Refactor frontend auth to the shared folder and hook it up to both the
portal and editor so they share the same system. Also adds various tasks
to help run the portal, including `task dev:portal` to spawn the portal
with the backend, and `task dev:portal:proxy` to spawn the editor,
portal and backend, and a reverse proxy (at localhost:3000) to allow you
to use both at once to simulate how this will actually be deployed,
allowing you to check whether the seamless transition between the two
actually works.
2026-06-22 16:22:36 +00:00

23 lines
700 B
TypeScript

/**
* Role helpers shared across apps.
*
* The Spring backend serialises authorities into a single string (e.g.
* "ROLE_ADMIN" or a space/comma separated list). Supabase carries roles in
* app_metadata. Both normalise through {@link isAdminRole}.
*/
const ADMIN_TOKENS = new Set(["ADMIN", "ROLE_ADMIN"]);
/**
* True when the supplied role string grants admin access. Tolerates a single
* role ("ROLE_ADMIN"), a space/comma separated list, and casing differences.
*/
export function isAdminRole(role: string | null | undefined): boolean {
if (!role) return false;
return role
.toUpperCase()
.split(/[\s,]+/)
.filter(Boolean)
.some((token) => ADMIN_TOKENS.has(token));
}