Skip to content

Commit

Permalink
Merge pull request #861 from KEEPER31337/feature/로그아웃_401_에러_처리_#859
Browse files Browse the repository at this point in the history
Feature/로그아웃 401 에러 처리
  • Loading branch information
publdaze authored Dec 11, 2023
2 parents 4cb60ab + 379cc93 commit 343c0a4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/api/authApi.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { useMutation } from 'react-query';
import { useNavigate } from 'react-router-dom';
import axios from 'axios';
import axios, { AxiosError } from 'axios';
import { useSetRecoilState } from 'recoil';
import memberState from '@recoil/member.recoil';

const useSignOutMutation = () => {
const fetcher = () => axios.post(`/sign-out`);

const navigate = useNavigate();
const setMemberState = useSetRecoilState(memberState);

const fetcher = () => axios.post(`/sign-out`);
const signOut = () => {
navigate('/');
setMemberState(null);
};

return useMutation(fetcher, {
onSuccess: () => {
navigate('/');
setMemberState(null);
signOut();
},
onError: (error) => {
const errorStatusCode = (error as AxiosError).response?.status;
if (errorStatusCode === 401) {
signOut();
}
},
});
};
Expand Down

0 comments on commit 343c0a4

Please sign in to comment.