diff --git a/src/App.tsx b/src/App.tsx index 3259605..1040ca7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,7 +6,7 @@ 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"; +import { loginAction } from "./store/user/loginUserSlice"; function App() { const Views = () => useRoutes(routes); @@ -14,7 +14,7 @@ function App() { const getUser = () => { user.detail().then((res: any) => { const data = res.data; - dispatch(logoutAction(data.user)); + dispatch(loginAction(data)); }); }; if (getToken()) { diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 06f84d9..e9c7fc0 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(loginAction(data.user)); + dispatch(loginAction(data)); setLoading(false); navigate("/"); }); diff --git a/src/store/user/loginUserSlice.ts b/src/store/user/loginUserSlice.ts index f0e6c11..effcebc 100644 --- a/src/store/user/loginUserSlice.ts +++ b/src/store/user/loginUserSlice.ts @@ -2,11 +2,13 @@ import { createSlice } from "@reduxjs/toolkit"; type UserStoreInterface = { user: any; + departments: any; isLogin: boolean; }; let defaultValue: UserStoreInterface = { user: null, + departments: null, isLogin: false, }; @@ -17,11 +19,14 @@ const loginUserSlice = createSlice({ }, reducers: { loginAction(stage, e) { + console.log(e); stage.value.user = e.payload.user; + stage.value.departments = e.payload.departments; stage.value.isLogin = true; }, logoutAction(stage) { stage.value.user = null; + stage.value.departments = null; stage.value.isLogin = false; }, },