Commit 9b875917 authored by Ermolaev Timur's avatar Ermolaev Timur

#92 исправил ошибку при выходе из профиля

parent 37bf7db6
...@@ -100,6 +100,7 @@ router.delete('/sessions', async(req: Request, res: Response):Promise<void | obj ...@@ -100,6 +100,7 @@ router.delete('/sessions', async(req: Request, res: Response):Promise<void | obj
if(!user) return res.send({successMsg}); if(!user) return res.send({successMsg});
user.token = nanoid(); user.token = nanoid();
await user.save(); await user.save();
return res.send(successMsg)
}) })
......
...@@ -18,8 +18,8 @@ const ProfileBlock = () => { ...@@ -18,8 +18,8 @@ const ProfileBlock = () => {
setAnchorEl(null); setAnchorEl(null);
}; };
const logout = async () => { const logout = () => {
await dispatch(logoutUser(navigate)); dispatch(logoutUser(navigate));
handleClose() handleClose()
} }
return <> return <>
...@@ -37,7 +37,7 @@ const ProfileBlock = () => { ...@@ -37,7 +37,7 @@ const ProfileBlock = () => {
> >
<MenuItem component={NavLink} to="/profile/test" color="inherit" onClick={handleClose}>Profile</MenuItem> <MenuItem component={NavLink} to="/profile/test" color="inherit" onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={logout}>Logout</MenuItem> <MenuItem onClick={()=>{logout()}}>Logout</MenuItem>
</Menu> </Menu>
</> </>
}; };
......
...@@ -85,13 +85,9 @@ export const forgottenPassword = (userData, navigate) => { ...@@ -85,13 +85,9 @@ export const forgottenPassword = (userData, navigate) => {
} }
export const logoutUser = (navigate) => { export const logoutUser = (navigate) => {
return async (dispatch, getState) => { return async (dispatch) => {
try { try {
await axios.delete("/users/sessions", { await axios.delete("/users/sessions");
headers: {
'Authorization': getState().users.user?.token
}
});
dispatch(logoutUserSuccess()); dispatch(logoutUserSuccess());
navigate("/"); navigate("/");
dispatch(showNotification("Вы успешно вышли")); dispatch(showNotification("Вы успешно вышли"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment