"use client"; import { useAuth } from "@/hooks/useAuth"; import { getStoredToken, loginWithRedirect } from "@/lib/auth"; import { useEffect } from "react"; const ADMIN_ROLES = ["platform_admin", "tenant_admin"]; /** محافظ پنل ادمین — SSO مرکزی + نقش platform_admin یا tenant_admin. */ export function AdminAuthGuard({ children }: { children: React.ReactNode }) { const { loading, user } = useAuth(); const hasAdminRole = ADMIN_ROLES.some((r) => user?.roles?.includes(r)); useEffect(() => { if (loading) return; if (!getStoredToken()) { void loginWithRedirect("/admin/tenants"); } }, [loading]); if (loading) { return
در حال بررسی ورود...
; } if (!getStoredToken()) { returnدر حال هدایت به ورود مرکزی...
; } if (!hasAdminRole) { return (دسترسی به پنل ادمین ندارید
فقط مدیر پلتفرم یا مدیر tenant میتوانند وارد این بخش شوند.