import type { ReactNode } from "react"; import { useT } from "../i18n/I18nProvider"; import { LoginPage } from "./LoginPage"; import { useAuth } from "./AuthProvider"; import type { Role } from "./AuthProvider"; /* Route guard, now wired into router.tsx. * * This is the client-side half only. It decides what to *render*; it is not * access control. The server authorises every request independently, and the * image bytes go through the auth-checked handoff (SPEC 3.3), because an * unguessable URL is not access control either. Deleting this file would * expose no data -- it would only make the app render pages whose requests * then 401. */ export function RequireAuth({ children, roles, }: { children: ReactNode; /** When given, the signed-in user must hold one of these roles. */ roles?: Role[]; }) { const t = useT(); const { state, can } = useAuth(); if (state.status === "loading") { return
{t("common.loading")}
; } if (state.status === "anonymous") { return{t("auth.unavailable")}
{t("auth.forbidden")}