hyapp-admin-platform/ops-center/src/OpsCenterEntry.jsx

27 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 <PageSkeleton />;
}
return <OpsCenterApp can={can} />;
}