-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
회원탈퇴 훅에서 로그아웃 전역변수 변동, 엑세스토큰을 로컬 스토리지에서 삭제 Issues #70
- Loading branch information
김병현
authored and
김병현
committed
Sep 16, 2023
1 parent
c9c3323
commit 57bf623
Showing
2 changed files
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import { useMutation } from 'react-query'; | ||
import axios from 'axios'; | ||
import { useDispatch } from 'react-redux'; // <-- 이 부분을 추가하세요. | ||
import { setLogoutState } from '../reducer/member/loginSlice'; | ||
|
||
export function useDeleteMember() { | ||
return useMutation(async () => { | ||
const response = await axios.delete(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com/members/`); | ||
const dispatch = useDispatch(); // <-- useDispatch를 호출해 dispatch 함수를 가져옵니다. | ||
|
||
return useMutation(async () => { | ||
const response = await axios.delete(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com/members`, {}); | ||
|
||
if (response.status !== 204) { | ||
throw new Error('Failed to delete member'); | ||
} | ||
}, { | ||
onSuccess: () => { | ||
alert('회원탈퇴 되었습니다!'); | ||
// 토큰 삭제 | ||
localStorage.removeItem('accessToken'); | ||
|
||
// 로그아웃 상태로 변경 | ||
dispatch(setLogoutState()); | ||
|
||
// 페이지 새로고침 (선택사항) | ||
window.location.reload(); | ||
} | ||
}); | ||
} | ||
} |