feat(admin-portal): 完整实现 admin-portal 管理端微前端
包含 src 全部实现、Dockerfile、配置文件等
This commit is contained in:
60
apps/admin-portal/src/app/admin/layout.tsx
Normal file
60
apps/admin-portal/src/app/admin/layout.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
"use client";
|
||||
|
||||
import { type ReactNode, useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { GraphQLProvider } from "@/providers/graphql-provider";
|
||||
import { AuthProvider, useAuth } from "@/providers/auth-provider";
|
||||
import { ToastProvider } from "@/providers/toast-provider";
|
||||
import { AdminShell } from "@/components/admin-shell";
|
||||
import { MswInitializer } from "@/components/msw-initializer";
|
||||
import { WebVitalsInitializer } from "@/components/web-vitals-initializer";
|
||||
|
||||
function AuthGuard({ children }: { children: ReactNode }) {
|
||||
const { isAuthenticated, isLoading } = useAuth();
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoading && !isAuthenticated) {
|
||||
router.replace("/login");
|
||||
}
|
||||
}, [isLoading, isAuthenticated, router]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
minHeight: "100vh",
|
||||
}}
|
||||
>
|
||||
<p style={{ color: "var(--color-ink-muted)" }}>加载中...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!isAuthenticated) return null;
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
export default function AdminLayout({ children }: { children: ReactNode }) {
|
||||
const [mswReady, setMswReady] = useState(false);
|
||||
|
||||
return (
|
||||
<GraphQLProvider>
|
||||
<WebVitalsInitializer />
|
||||
<MswInitializer onReady={() => setMswReady(true)} />
|
||||
{mswReady && (
|
||||
<AuthProvider>
|
||||
<ToastProvider>
|
||||
<AuthGuard>
|
||||
<AdminShell>{children}</AdminShell>
|
||||
</AuthGuard>
|
||||
</ToastProvider>
|
||||
</AuthProvider>
|
||||
)}
|
||||
</GraphQLProvider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user