guild_front/src/hooks/useLogout.js

20 lines
515 B
JavaScript
Raw Normal View History

2023-05-31 08:36:15 +03:00
import { useDispatch, useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";
import { auth } from "../redux/outstaffingSlice";
import { getRole } from "../redux/roleSlice";
export const useLogout = () => {
const dispatch = useDispatch();
const userRole = useSelector(getRole);
const navigate = useNavigate();
const logout = () => {
localStorage.clear();
dispatch(auth(false));
2023-05-31 08:36:15 +03:00
navigate(userRole === "ROLE_DEV" ? "/authdev" : "/auth");
};
2023-05-31 08:36:15 +03:00
return { logout };
};