Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] 로그인 관리 sessionStorage에서 localStorage로 변경해요 #105

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
};
Loading