diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 89d3749..65bdd84 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -37,6 +37,7 @@ export default function App(): React.ReactElement { ckey: "debug", email: "debug@debug.debug", groups: ["admin"], + manageable: ["mentor"], isStaff: true, isManagement: true, }); @@ -68,6 +69,32 @@ export default function App(): React.ReactElement { .catch((error) => { console.error("Auth error:", error); window.location.href = "/api/auth/login"; + setAuthLoading(false); + return; + }); + + // Fetch allowed groups from backend + fetch(`${apiPath}/Authentik/AllowedGroups`, { + credentials: "include", + }) + .then((response) => { + if (!response.ok) { + throw new Error("Failed to fetch allowed groups"); + } + return response.json(); + }) + .then((json: { manageable: string[] }) => { + setUser((exitingUser) => { + if (exitingUser) { + return { + ...exitingUser, + manageable: json.manageable, + }; + } + }); + }) + .catch((error) => { + console.error("Auth error:", error); }) .finally(() => { setAuthLoading(false); @@ -147,7 +174,7 @@ export default function App(): React.ReactElement { )} - {user?.isManagement && ( + {user?.manageable?.length && ( <> | diff --git a/frontend/src/types/global.ts b/frontend/src/types/global.ts index b2a7b9e..4ed731c 100644 --- a/frontend/src/types/global.ts +++ b/frontend/src/types/global.ts @@ -5,6 +5,7 @@ export type User = { ckey: string; email: string; groups: string[]; + manageable: string[]; isStaff: boolean; isManagement: boolean; };