mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2026-09-03 05:10:16 +03:00
# 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.
23 lines
700 B
TypeScript
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));
|
|
}
|