Files
meezi/web/dashboard/src/lib/auth-permissions.ts
T

39 lines
1.0 KiB
TypeScript
Raw Normal View History

import { BRANCH_ONLY_NAV_GROUP, type NavGroupId } from "@/lib/sidebar-nav";
/** Cafe owner (HQ) — billing, taxes, branches. */
export function isCafeOwner(role: string | undefined): boolean {
return role === "Owner";
}
/** Logged in as a branch-scoped employee (JWT branchId). */
export function isBranchAccount(branchId: string | null | undefined): boolean {
return !!branchId;
}
export const OWNER_ONLY_NAV_KEYS = ["subscription", "taxes", "branches"] as const;
export function canSeeNavGroup(
groupId: NavGroupId,
role: string | undefined,
branchId: string | null | undefined
): boolean {
if (isBranchAccount(branchId) && groupId !== BRANCH_ONLY_NAV_GROUP) {
return false;
}
return true;
}
export function canSeeNavItem(
key: string,
role: string | undefined,
branchId: string | null | undefined
): boolean {
if ((OWNER_ONLY_NAV_KEYS as readonly string[]).includes(key) && !isCafeOwner(role)) {
return false;
}
if (key === "branches" && isBranchAccount(branchId)) {
return false;
}
return true;
}