diff --git a/frontend/src/Route.tsx b/frontend/src/Route.tsx index 7ef429d..f244493 100644 --- a/frontend/src/Route.tsx +++ b/frontend/src/Route.tsx @@ -1,4 +1,4 @@ -import { Routes, Route, createBrowserRouter, RouterProvider } from "react-router-dom"; +import { Routes, Route, createBrowserRouter, RouterProvider, useNavigate } from "react-router-dom"; import { ScrollRestoration } from "react-router-dom"; import Login from '@/views/Login' import Register from '@/views/Register' @@ -6,6 +6,8 @@ import Profile from '@/views/profile/Profile' import Textures from '@/views/profile/Textures' import Security from '@/views/profile/Security' import Layout from '@/views/Layout' +import { useAtomValue } from "jotai"; +import { token } from "@/store/store"; const router = createBrowserRouter([ { path: "*", Component: Root }, @@ -16,11 +18,14 @@ function Root() { <> }> + 123

} /> + 404

} /> } /> } /> - } /> - } /> - } /> + + } /> + } /> + } />
@@ -38,3 +43,12 @@ export function PageRoute() { } +function NeedLogin({ children }: { children: JSX.Element }) { + const t = useAtomValue(token) + const navigate = useNavigate(); + if (t == "") { + navigate("/login") + return + } + return <> {children} +} \ No newline at end of file diff --git a/frontend/src/views/Layout.tsx b/frontend/src/views/Layout.tsx index 5a25699..1e881e5 100644 --- a/frontend/src/views/Layout.tsx +++ b/frontend/src/views/Layout.tsx @@ -34,7 +34,8 @@ import Container from '@mui/material/Container'; import PersonIcon from '@mui/icons-material/Person'; import SecurityIcon from '@mui/icons-material/Security'; import SettingsIcon from '@mui/icons-material/Settings'; -import useTilg from 'tilg' +import { Link } from "react-router-dom"; + const drawerWidth = 240; const DrawerOpen = atom(false) @@ -58,8 +59,6 @@ const Layout = memo(function Layout() { const theme = useTheme(); const [err, setErr] = useAtom(LayoutAlertErr) - useTilg() - return (<> @@ -132,7 +131,9 @@ const MyToolbar = memo(function MyToolbar() { ) } - {server.data?.meta.serverName ?? "皮肤站"} + + {server.data?.meta.serverName ?? "皮肤站"} + {nowUser.name != "" && (
@@ -173,7 +174,7 @@ const MyToolbar = memo(function MyToolbar() { }) const MyList = memo(function MyList(p: { list: ListItem[] }) { - useTilg() + return ( <> @@ -251,7 +252,7 @@ const MyDrawer = function MyDrawer() { } ] as ListItem[], []) - useTilg() + return (<> {userinfo.data && ( diff --git a/frontend/src/views/profile/Profile.tsx b/frontend/src/views/profile/Profile.tsx index 1be2283..242791f 100644 --- a/frontend/src/views/profile/Profile.tsx +++ b/frontend/src/views/profile/Profile.tsx @@ -17,7 +17,6 @@ import type { ReactSkinview3dOptions } from "react-skinview3d" import { WalkingAnimation } from "skinview3d" import type { SkinViewer } from "skinview3d" import Skeleton from '@mui/material/Skeleton'; -import useTilg from 'tilg'; import useTitle from '@/hooks/useTitle'; const Profile = function Profile() { @@ -45,7 +44,7 @@ const Profile = function Profile() { }, [SkinInfo.data]) - useTilg() + return ( <> diff --git a/frontend/src/views/profile/Security.tsx b/frontend/src/views/profile/Security.tsx index 10622c9..40dcfe5 100644 --- a/frontend/src/views/profile/Security.tsx +++ b/frontend/src/views/profile/Security.tsx @@ -7,10 +7,11 @@ import { useEffect, useState } from "react"; import { produce } from 'immer' import { changePasswd } from "@/apis/apis"; import { useAtom, useSetAtom } from "jotai"; -import { LayoutAlertErr, token } from "@/store/store"; +import { LayoutAlertErr, token, user } from "@/store/store"; import Loading from "@/components/Loading"; import { ApiErr } from "@/apis/error"; import { useNavigate } from "react-router-dom"; +import useTitle from "@/hooks/useTitle"; export default function Security() { const [pass, setPass] = useState({ @@ -23,7 +24,9 @@ export default function Security() { const [nowToken, setToken] = useAtom(token) const [load, setLoad] = useState(false) const setLayoutErr = useSetAtom(LayoutAlertErr) + const setUser = useSetAtom(user) const navigate = useNavigate(); + useTitle("安全设置") useEffect(() => { if (pass.pass1 != pass.pass2 && pass.pass2 != "") { @@ -43,7 +46,7 @@ export default function Security() { return } setLayoutErr(String(e)) - }).finally(() => setLoad(false)).then(() => [navigate("/login"), setToken("no")]) + }).finally(() => setLoad(false)).then(() => [navigate("/login"), setToken(""), setUser({ name: "", uuid: "" })]) } diff --git a/frontend/src/views/profile/Textures.tsx b/frontend/src/views/profile/Textures.tsx index 7537f2f..87cc30b 100644 --- a/frontend/src/views/profile/Textures.tsx +++ b/frontend/src/views/profile/Textures.tsx @@ -81,7 +81,7 @@ const Textures = function Textures() { finally(() => setLoading(false)) } - useTilg() + return (<>