30 lines
1.6 KiB
TypeScript
30 lines
1.6 KiB
TypeScript
export type AuthPath = "public" | "machine" | "clock" | "dashboard" | "admin";
|
|
export function classifyAuthPath(pathname: string): AuthPath {
|
|
if (pathname === "/api/health" || pathname.startsWith("/api/auth/")) return "public";
|
|
if (
|
|
pathname === "/api/purchase-orders/ingest" ||
|
|
pathname === "/api/purchase-orders/process-batch" ||
|
|
pathname === "/api/dn-batches/tick" ||
|
|
/^\/api\/purchase-orders\/by-number\/[^/]+\/items$/.test(pathname) ||
|
|
/^\/api\/purchase-orders\/[^/]+\/delivery-reconciliation$/.test(pathname) ||
|
|
/^\/api\/delivery-notes\/[^/]+\/slip$/.test(pathname)
|
|
) return "machine";
|
|
if (
|
|
pathname.startsWith("/dashboard/settings") ||
|
|
pathname.startsWith("/dashboard/chat") ||
|
|
pathname.startsWith("/dashboard/change-requests") ||
|
|
pathname.startsWith("/api/admin/") ||
|
|
pathname.startsWith("/api/ask/") ||
|
|
pathname.startsWith("/api/chat") ||
|
|
pathname.startsWith("/api/agent/")
|
|
) return "admin";
|
|
if (/^\/api\/clock\/events\/[^/]+\/correct$/.test(pathname)) return "admin";
|
|
if (pathname.startsWith("/api/pb-files/")) return "dashboard";
|
|
if (pathname === "/api/purchase-orders/upload" ||
|
|
/^\/api\/purchase-orders\/[^/]+\/status$/.test(pathname)) return "dashboard";
|
|
if (/^\/api\/dn-batches\/[^/]+\/pages\/[^/]+$/.test(pathname) ||
|
|
/^\/api\/purchase-orders\/[^/]+\/(document|pages\/[^/]+)$/.test(pathname)) return "dashboard";
|
|
if (pathname === "/clock" || pathname.startsWith("/clock/") || pathname.startsWith("/api/clock/") ||
|
|
pathname === "/api/delivery-notes/upload") return "clock";
|
|
return pathname.startsWith("/api/") ? "admin" : "dashboard";
|
|
}
|