-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: LoginState, UserState, logout을 전부 초기화 하는 useResetUserInfo훅 구현 * fix: 기존 postWithdraw 함수에서 로그아웃 부분 제거 * fix: Withdraw에서 탈퇴 성공 시 useResetUserInfo 불러와서 정보 삭제하도록 수정 * refactor: 기존 resetUserInfo으로 분리했던 코드를 하나로 통합 * refactor: postWithdraw 로직을 mutation을 활용하여 분리 및 alert 대신 errorboundary로 수정 * fix: UserState 관련 코드 삭제
- Loading branch information
Showing
4 changed files
with
93 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,9 @@ | ||
import { isAxiosError } from 'axios'; | ||
|
||
import { authClient } from '@/apis'; | ||
import { PostWithdrawResponse, AuthErrorData } from '@/home/types/Auth.type'; | ||
import { api } from '@/service/TokenService'; | ||
|
||
export const postWithdraw = async (): Promise<PostWithdrawResponse> => { | ||
try { | ||
await authClient.post( | ||
'/auth/withdraw', | ||
{}, | ||
{ | ||
headers: api.headers, | ||
} | ||
); | ||
api.logout(); | ||
return { success: true }; | ||
} catch (error) { | ||
if (isAxiosError<AuthErrorData>(error)) return { success: false, error }; | ||
return Promise.reject(error); | ||
} | ||
export const postWithdraw = async (data: object) => { | ||
const res = await authClient.post('/auth/withdraw', data, { | ||
headers: api.headers, | ||
}); | ||
return res.data; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { postWithdraw } from '@/home/apis/postWithdraw'; | ||
|
||
import { useResetUserInfo } from './useResetUserInfo'; | ||
|
||
export const usePostWithdraw = () => { | ||
const resetUserInfo = useResetUserInfo(); | ||
|
||
return useMutation({ | ||
mutationFn: postWithdraw, | ||
onSuccess: () => { | ||
resetUserInfo(); | ||
}, | ||
throwOnError: true, | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useSetRecoilState } from 'recoil'; | ||
|
||
import { LogInState } from '@/home/recoil/LogInState'; | ||
import { api } from '@/service/TokenService'; | ||
|
||
export const useResetUserInfo = () => { | ||
const resetLoginState = useSetRecoilState(LogInState); | ||
|
||
return () => { | ||
resetLoginState(false); | ||
api.logout(); | ||
}; | ||
}; |