diff --git a/app/app/(admin)/admin/ana/page.tsx b/app/app/(admin)/admin/ana/page.tsx index 1d5835598..f4def8561 100644 --- a/app/app/(admin)/admin/ana/page.tsx +++ b/app/app/(admin)/admin/ana/page.tsx @@ -1,17 +1,17 @@ import UsageByModel from "./usage-by-model-chart"; import UserByMap from "./user-by-map"; -import { getSession } from "@/lib/auth"; -import { isName, ADMIN_LIST } from "@/lib/auth_list"; -import { redirect } from "next/navigation"; +// import { getSession } from "@/lib/auth"; +// import { isName, ADMIN_LIST } from "@/lib/auth_list"; +// import { redirect } from "next/navigation"; import { Flex } from "antd"; export default async function AdminPage() { - const session = await getSession(); - const name = session?.user?.email || session?.user?.name; - if (!(name && ADMIN_LIST.includes(name))) { - // Replace '/dashboard' with the desired redirect path - redirect("/"); - } + // const session = await getSession(); + // const name = session?.user?.email || session?.user?.name; + // if (!(name && ADMIN_LIST.includes(name))) { + // // Replace '/dashboard' with the desired redirect path + // redirect("/"); + // } return ( <> diff --git a/app/app/(admin)/admin/layout.tsx b/app/app/(admin)/admin/layout.tsx index c60375cf8..a760b9960 100644 --- a/app/app/(admin)/admin/layout.tsx +++ b/app/app/(admin)/admin/layout.tsx @@ -1,6 +1,9 @@ "use client"; -import React, { ReactNode, useState } from "react"; +import { useSession } from "next-auth/react"; +import { redirect } from "next/navigation"; +import { ADMIN_LIST } from "@/lib/auth_list"; +import React, { ReactNode, useEffect, useState } from "react"; import { MenuFoldOutlined, MenuUnfoldOutlined, @@ -15,12 +18,23 @@ const { Header, Sider, Content } = Layout; function MainLayout({ children }: { children: ReactNode }) { // const [theme, setTheme] = useState('dark'); - + const { data, status } = useSession(); + const name = data?.user?.email || data?.user?.name; + // console.log('name', name, data, status) const [collapsed, setCollapsed] = useState(false); const { token: { colorBgContainer, borderRadiusLG, colorBgLayout }, } = theme.useToken(); + // 客户端才执行 + useEffect(() => { + // 用户已登录,且没设置密码 + // if (status === "loading") return; + if (status === "authenticated" && !(name && ADMIN_LIST.includes(name))) { + redirect("/"); + } + // 状态变化时,重新判断 + }, [name, status]); return ( + + + {/*
+
+ + ); +} diff --git a/app/app/(admin)/components/sidebar.tsx b/app/app/(admin)/components/sidebar.tsx index 89c98108a..0287214ba 100644 --- a/app/app/(admin)/components/sidebar.tsx +++ b/app/app/(admin)/components/sidebar.tsx @@ -68,33 +68,15 @@ const SideBar: React.FC = () => { setCurrent(e.key); router.push(e.key); }; - useEffect(() => { - // 如果按钮和路径不相等,那其实应该跳转到按钮的网址 - if (current != pathname) { - router.push(current); - } - }, [current, pathname, router]); // useEffect(() => { - // const handleStart = () => setLoading(true) - // const handleComplete = () => setLoading(false); - // router.events.on('routeChangeStart', handleStart); - // router.events.on('routeChangeComplete', handleStop); - // router.events.on('routeChangeError', handleStop); - // - // return () => { - // router. - // } - // - // }, [router]); + // // 如果按钮和路径不相等,那其实应该跳转到按钮的网址 + // if (current != pathname) { + // router.push(current); + // } + // }, [current, pathname, router]); return ( <> - {/**/}