登录初步

This commit is contained in:
禺狨 2023-03-23 16:42:01 +08:00
parent 4e03c1d82d
commit 4b965f26f5
3 changed files with 16 additions and 2 deletions

View File

@ -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 (
<Suspense fallback={<LoadingPage />}>

View File

@ -10,7 +10,7 @@ export function login(
email: email,
password: password,
captcha_key: captchaKey,
captcha_value: captchaVal,
captcha_val: captchaVal,
});
}

View File

@ -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("/");
});