Skip to content

Commit

Permalink
fix logout error
Browse files Browse the repository at this point in the history
  • Loading branch information
Danush99 committed Aug 15, 2023
1 parent 0a6b8e6 commit 710ac95
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/components/AppbarComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ const AppBar = styled(MuiAppBar, {
export default function AppbarComponent({ open, toggleDrawer }) {

const dispatch = useDispatch();
const navigate = useNavigate();
const user: User | null = useSelector((state: AppState) => state.user.user);
const token = user.token;

const handleLogout = async () => {
await authServices.logout(token);
dispatch(removeUser());
const isLogOut = await authServices.logout(token);
if(isLogOut){
dispatch(removeUser());
navigate("/");
}
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/services/AuthServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const logout = async (token: string) => {
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
const response = await axios.post("/auth/logout", data);
if(response.status === 200 || response.status === 202){
window.location.href = '/'
return true;
}
} catch (error) {
ToasterMessage.errorMessage({
Expand Down
7 changes: 1 addition & 6 deletions src/services/HttpServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const axiosInstance = Axios.create({
axiosInstance.interceptors.response.use((response) => {
return response;
}, (error) => {
if ([403].includes(error?.response?.status)) {
if ([401].includes(error?.response?.status)) {
ToasterMessage.errorMessage({
error: error,
custom_message: "Your session has expired. Please login again."
Expand All @@ -24,11 +24,6 @@ axiosInstance.interceptors.response.use((response) => {
custom_message: error.response.data.message
})
}
else{
ToasterMessage.errorMessage({
error: error,
});
}
return Promise.reject(error);
});

Expand Down

0 comments on commit 710ac95

Please sign in to comment.