"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 (

加载中...

); } if (!isAuthenticated) return null; return <>{children}; } export default function AdminLayout({ children }: { children: ReactNode }) { const [mswReady, setMswReady] = useState(false); return ( setMswReady(true)} /> {mswReady && ( {children} )} ); }