import { Link, Navigate } from "@tanstack/solid-router"; import { type ParentProps, Show } from "solid-js"; import type { Role } from "@/api/client"; import { formatApiError } from "@/api/client"; import { Alert } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { IconHome, IconLock } from "@/components/ui/icons"; import { PageSpinner } from "@/components/ui/page-spinner"; import { hasExactRole, roleInRange } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; function AccessDeniedCard() { const t = useT(); return (

403

{t("common.accessDenied")}

{t("errors.accessDeniedDescription")}

{t("common.goHome")}
); } export function RouteGuard( props: ParentProps<{ minRole?: Role; /** Inclusive upper bound (e.g. maxRole: "manager" excludes admin). */ maxRole?: Role; /** When set, only this exact role may enter (e.g. student-only pages). */ exactRole?: Role; }>, ) { const auth = useAuth(); const t = useT(); const allowed = (role: Role) => { if (props.exactRole) return hasExactRole(role, props.exactRole); if (props.minRole || props.maxRole) return roleInRange(role, props.minRole, props.maxRole); return true; }; return ( }>

{formatApiError(auth.error())}

}> }> {(u) => ( }> {props.children} )}
); }