import { ShieldAlert } from "lucide-react"; import { useAuth } from "react-oidc-context"; import { t } from "../../lib/i18n"; import { resolveProfileRole } from "../../lib/role"; interface Props { resourceToken: "audit" | "clients" | "consents"; } export function ForbiddenMessage({ resourceToken }: Props) { const auth = useAuth(); const rawProfile = auth.user?.profile as Record | undefined; const role = resolveProfileRole(rawProfile); let explanation = t( "msg.dev.forbidden.default", "You do not have permission to access this resource. Contact your administrator.", ); if (role === "rp_admin") { explanation = t( "msg.dev.forbidden.rp_admin", "RP administrators can only access resources for their assigned applications.", ); } else if (role === "tenant_admin") { explanation = t( "msg.dev.forbidden.tenant_admin", "Your tenant administrator permission is missing, misconfigured, or expired.", ); } else if (role === "user" || role === "tenant_member") { if (resourceToken === "consents") { explanation = t( "msg.dev.forbidden.user.consents", "Viewing consent records for this application requires an RP administrator, consent read, or consent revoke relationship. Request access from an administrator if needed.", ); } else if (resourceToken === "audit") { explanation = t( "msg.dev.forbidden.user.audit", "Viewing audit logs for this application requires an RP administrator or audit read relationship. Request access from an administrator if needed.", ); } else { explanation = t( "msg.dev.forbidden.user.clients", "Standard user accounts can use this feature only when an operational or administrative relationship is granted for the target RP. Request access from an administrator if needed.", ); } } const resourceLabel = resourceToken === "audit" ? t("ui.dev.audit.title", "Audit Logs") : resourceToken === "consents" ? t("ui.dev.clients.consents.title", "User Consent Grants") : t("ui.dev.clients.registry.subtitle", "Connected Applications"); const title = t("msg.dev.forbidden.title", "Access denied: {{resource}}", { resource: resourceLabel, }); return (

{title}

{explanation}

); }