Skip to content

Commit

Permalink
#206 feat: Token 에러 시 캐시 삭제 후 리다이렉션 핸들러를 반환하는 useTokenError 커스텀 훅 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzoo committed Aug 4, 2024
1 parent 98d0a50 commit c29a3f3
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/common/hook/useTokenError.ts
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 };
};

0 comments on commit c29a3f3

Please sign in to comment.