import { useEffect } from "react";
import { useAuth } from "@/app/auth/AuthProvider.jsx";
import { buildLoginRedirectPath } from "@/features/auth/loginRedirect.js";
import { PageSkeleton } from "@/shared/ui/PageSkeleton.jsx";
import { OpsCenterApp } from "./OpsCenterApp.jsx";
export function AuthenticatedOpsCenter({ targetWindow = window }) {
const { can, loading, user } = useAuth();
const loginPath = buildLoginRedirectPath(targetWindow.location);
useEffect(() => {
if (!loading && !user) {
// ops-center 是独立 HTML 入口,不能使用 SPA Navigate。登录页沿用主站既有 `redirect` 协议,
// 成功后 LoginPage 会识别 /ops-center/ 为 document entry,再通过 location.replace 回到完整路径。
targetWindow.location.replace(loginPath);
}
}, [loading, loginPath, targetWindow, user]);
if (loading || !user) {
// AuthProvider 可能正在用 refresh cookie 更新过期 token,完成前不能挂载 OpsCenterApp;
// 否则 dashboard 的并发请求会先拿旧 token 返回 401,且认证完成后没有新的挂载时机自动恢复。
return ;
}
return ;
}