Wire production domain, CORS for tenant subdomains, celery volume mounts, and nginx reverse proxy configs for apex, API, identity, auth, and wildcard tenants. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
"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 <p className="text-sm text-gray-500">در حال بررسی ورود...</p>;
|
||
}
|
||
|
||
if (!getStoredToken()) {
|
||
return <p className="text-sm text-gray-500">در حال هدایت به ورود مرکزی...</p>;
|
||
}
|
||
|
||
if (!hasAdminRole) {
|
||
return (
|
||
<div className="mx-auto mt-16 max-w-md rounded-2xl border border-amber-100 bg-amber-50 p-6 text-center">
|
||
<p className="font-semibold text-amber-800">دسترسی به پنل ادمین ندارید</p>
|
||
<p className="mt-2 text-sm text-amber-700">
|
||
فقط مدیر پلتفرم یا مدیر tenant میتوانند وارد این بخش شوند.
|
||
</p>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
return <>{children}</>;
|
||
}
|