From 4b965f26f56f4c3aac35fd939dc015aef0581ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Thu, 23 Mar 2023 16:42:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E5=88=9D=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 14 ++++++++++++++ src/api/login.ts | 2 +- src/pages/login/index.tsx | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index cc355fc..3259605 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,9 +3,23 @@ import routes from "./routes"; import "./App.scss"; import { Suspense } from "react"; import LoadingPage from "./pages/loading"; +import { user } from "./api/index"; +import { getToken } from "./utils/index"; +import { useDispatch } from "react-redux"; +import { logoutAction } from "./store/user/loginUserSlice"; function App() { const Views = () => useRoutes(routes); + const dispatch = useDispatch(); + const getUser = () => { + user.detail().then((res: any) => { + const data = res.data; + dispatch(logoutAction(data.user)); + }); + }; + if (getToken()) { + getUser(); + } return ( }> diff --git a/src/api/login.ts b/src/api/login.ts index edc10b4..0ff7cce 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -10,7 +10,7 @@ export function login( email: email, password: password, captcha_key: captchaKey, - captcha_value: captchaVal, + captcha_val: captchaVal, }); } diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index c9d5698..06f84d9 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -80,7 +80,7 @@ const LoginPage: React.FC = () => { const getUser = () => { user.detail().then((res: any) => { const data = res.data; - dispatch(logoutAction(data.user)); + dispatch(loginAction(data.user)); setLoading(false); navigate("/"); });