-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#206 feat: Token 에러 시 캐시 삭제 후 리다이렉션 핸들러를 반환하는 useTokenError 커스텀 훅 생성
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { PATH } from '@/shared/constant/path'; | ||
import { useAuth } from '@/shared/store/auth'; | ||
import { useToastAction } from '@/shared/store/toast'; | ||
|
||
export const useTokenError = () => { | ||
const { logout } = useAuth(); | ||
|
||
const { createToast } = useToastAction(); | ||
|
||
const queryClient = useQueryClient(); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleTokenError = () => { | ||
logout(); | ||
|
||
localStorage.clear(); | ||
|
||
queryClient.clear(); | ||
|
||
navigate(PATH.ROOT); | ||
|
||
createToast('다시 로그인해주세요.'); | ||
}; | ||
|
||
return { handleTokenError }; | ||
}; |