Skip to content

Commit 5147625

Browse files
committed
Edit SITE_MAP to define UI Role guards
1 parent 7fdcb2f commit 5147625

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/lib/utils/roleChecker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface UserEntitlement {
4040
* - `required`: user needs at least one (OR logic) to view the page
4141
* - `optional`: additional roles that enable extra actions (e.g. create/delete buttons)
4242
*/
43-
export const PAGE_ROLES: Record<string, PageRoleConfig> = {
43+
export const SITE_MAP: Record<string, PageRoleConfig> = {
4444
// ── RBAC ──────────────────────────────────────────────
4545
"/rbac/roles": {
4646
required: [{ role: "CanGetRolesWithEntitlementCountsAtAllBanks" }],
@@ -202,7 +202,7 @@ export const PAGE_ROLES: Record<string, PageRoleConfig> = {
202202
*/
203203
export function getPageRoles(routeId: string): PageRoleConfig | undefined {
204204
const key = routeId.replace("/(protected)", "");
205-
return PAGE_ROLES[key];
205+
return SITE_MAP[key];
206206
}
207207

208208
/**

src/routes/(protected)/+layout.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script lang="ts">
22
import { page } from "$app/state";
33
import PageRoleCheck from "$lib/components/PageRoleCheck.svelte";
4-
import { PAGE_ROLES } from "$lib/utils/roleChecker";
4+
import { SITE_MAP } from "$lib/utils/roleChecker";
55
66
let { data, children } = $props();
77
88
let routeKey = $derived(page.route.id?.replace("/(protected)", "") || "");
9-
let pageRoles = $derived(PAGE_ROLES[routeKey]);
9+
let pageRoles = $derived(SITE_MAP[routeKey]);
1010
</script>
1111

1212
{#if pageRoles}

src/routes/(protected)/user/site-map/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { PAGE_ROLES, checkRoles } from "$lib/utils/roleChecker";
2+
import { SITE_MAP, checkRoles } from "$lib/utils/roleChecker";
33
import type { UserEntitlement, RoleRequirement } from "$lib/utils/roleChecker";
44
import { Check, X, Search } from "@lucide/svelte";
55
import MissingRoleAlert from "$lib/components/MissingRoleAlert.svelte";
@@ -44,7 +44,7 @@
4444
}
4545
4646
let allPages: PageEntry[] = $derived(
47-
Object.entries(PAGE_ROLES).map(([route, config]) => {
47+
Object.entries(SITE_MAP).map(([route, config]) => {
4848
const result = checkRoles(userEntitlements, config.required);
4949
return {
5050
route,

0 commit comments

Comments
 (0)