diff --git a/src/hooks/useWithdraw.ts b/src/hooks/useWithdraw.ts index 88135b5..fbec14e 100644 --- a/src/hooks/useWithdraw.ts +++ b/src/hooks/useWithdraw.ts @@ -1,19 +1,22 @@ import { useNavigate } from 'react-router-dom'; import { useToast } from '@/contexts/ToastContext'; import { withdrawUser } from '@/libs/apis/withdrawUser.api'; +import useUserStore from '@/store/useUserStore'; const useWithdraw = () => { const navigate = useNavigate(); const { openToast } = useToast(); + const { clearUser } = useUserStore(); const onWithdraw = async () => { try { const response = await withdrawUser(); - if (response.ok) { + if (response.code === 200) { localStorage.removeItem('accessToken'); localStorage.removeItem('refreshToken'); - openToast('계정이 성공적으로 탈퇴되었습니다.'); + clearUser(); + openToast('계정이 성공적으로 탈퇴되었습니다.', 'success'); navigate('/'); } else { throw new Error('계정 탈퇴 실패'); diff --git a/src/libs/apis/withdrawUser.api.ts b/src/libs/apis/withdrawUser.api.ts index f7c1fa1..e42c68f 100644 --- a/src/libs/apis/withdrawUser.api.ts +++ b/src/libs/apis/withdrawUser.api.ts @@ -1,9 +1,8 @@ import client from '@/libs/apis/clients'; -//현재 탈퇴하기 api는 나오지 않았는데 로직만 적어두었습니다 export const withdrawUser = async () => { try { - const res = await client.post('/auth/logout'); + const res = await client.delete('/api/members'); return res.data; } catch (error) { throw new Error(`Error post withdraw: ${error}`);