Skip to content

Commit

Permalink
[Refactor] 로그인 관리 sessionStorage에서 localStorage로 변경해요 (#105)
Browse files Browse the repository at this point in the history
* fix: sessionStorage를 localStorage로 변경

* fix: redirect에서 navigate로 변경하기
  • Loading branch information
eugene028 authored Sep 4, 2024
1 parent f36e5aa commit 42f68cb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/components/ApiErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sentry from '@sentry/react';
import { useQueryClient } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { redirect } from 'react-router-dom';
import { useNavigate } from 'react-router-dom';
import { toast } from 'react-toastify';
import RoutePath from '@/routes/routePath';
import { ReactNode } from 'react';
Expand All @@ -17,6 +17,7 @@ export default function ApiErrorBoundary({
children: ReactNode;
}) {
const queryClient = useQueryClient();
const navigate = useNavigate();

queryClient.getQueryCache().config = {
onError: (error) => handleError(error as AxiosError)
Expand All @@ -38,8 +39,8 @@ export default function ApiErrorBoundary({
case 401:
case 403:
toast.error(message);
sessionStorage.setItem('isLogin', 'false');
redirect(RoutePath.Home);
localStorage.setItem('isLogin', 'false');
navigate(RoutePath.Home);
break;
default:
toast.error(message);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/mutation/useLogout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function useLogout() {
const mutation = useMutation({
mutationFn: authApi.LOGOUT,
onSuccess: () => {
sessionStorage.clear();
localStorage.clear();
navigate(RoutePath.Home);
location.reload();
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/redirect/AuthServerRedirectNavigate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const AuthServerRedirectNavigate = () => {
const navigate = useNavigate();

useEffect(() => {
sessionStorage.setItem('isLogin', 'true');
localStorage.setItem('isLogin', 'true');
navigate(RoutePath.Dashboard);
}, [navigate]);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const isAuthenticated = () => {
const isLogin = sessionStorage.getItem('isLogin');
const isLogin = localStorage.getItem('isLogin');

return isLogin === 'true';
};

0 comments on commit 42f68cb

Please sign in to comment.