From c6901463c82852e42edfe9bb300db10cb19f8513 Mon Sep 17 00:00:00 2001 From: JongHyun Date: Tue, 6 Aug 2024 01:10:45 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=AC=B4=ED=95=9C=20=EB=A1=9C=EB=94=A9?= =?UTF-8?q?=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 2 +- src/loginPage/LoginPage.jsx | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 45350d2..9b177f6 100644 --- a/src/App.js +++ b/src/App.js @@ -26,7 +26,7 @@ const AxiosInterceptor = () => { console.log("Axios interceptor caught an error:", error); // 로그 추가 setCsrfToken(null); setUserTokenState({ isLogin: false }); - navigate("/"); + navigate("/", { replace: true }); // 리다이렉션 } return Promise.reject(error); } diff --git a/src/loginPage/LoginPage.jsx b/src/loginPage/LoginPage.jsx index 14c5b88..d09334e 100644 --- a/src/loginPage/LoginPage.jsx +++ b/src/loginPage/LoginPage.jsx @@ -1,7 +1,7 @@ import { Link, useNavigate } from "react-router-dom"; import { useRecoilValue } from "recoil"; import styled from "styled-components"; -import { UserTokenState } from "../atom/atom"; +import { tokenState, UserTokenState } from "../atom/atom"; import { useEffect } from "react"; const Wrapper = styled.div` @@ -29,12 +29,14 @@ const GoogleLoginBtn = styled.div` const LoginPage = () => { const navigate = useNavigate(); const UserToken = useRecoilValue(UserTokenState); + const Token = useRecoilValue(tokenState); useEffect(() => { - if (UserToken !== false) { + // UserToken이 null이 아니고, false가 아닌 경우에만 navigate 호출 + if (Token !== null && UserToken !== false) { navigate(`/HomePage`); } - }, [UserToken]); + }, [UserToken, navigate]); const handleGoogleLogin = () => { // 구글 로그인 화면으로 이동시키기 window.location.href = `${process.env.REACT_APP_HOST_URL}/oauth2/authorization/google`;