From f6d405fbe0d7a37bd1e83e92431ba7ee25e91f7d Mon Sep 17 00:00:00 2001 From: gilpop8663 Date: Tue, 5 Sep 2023 03:52:38 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20(#516)=20hasEssentialInfo=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EC=82=AD=EC=A0=9C=ED=96=88=EC=9D=84=20?= =?UTF-8?q?=EB=95=8C=20=EA=B0=9C=EC=9D=B8=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20?= =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=EC=9E=85=EB=A0=A5=ED=95=A0=20=EC=88=98=20?= =?UTF-8?q?=EC=9E=88=EB=8D=98=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 --- frontend/src/routes/PrivateRoute.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/PrivateRoute.tsx b/frontend/src/routes/PrivateRoute.tsx index ff90d2762..219060899 100644 --- a/frontend/src/routes/PrivateRoute.tsx +++ b/frontend/src/routes/PrivateRoute.tsx @@ -1,6 +1,8 @@ -import { PropsWithChildren } from 'react'; +import { PropsWithChildren, useContext } from 'react'; import { Navigate } from 'react-router-dom'; +import { AuthContext } from '@hooks/context/auth'; + import { PATH } from '@constants/path'; import { getCookieToken } from '@utils/cookie'; @@ -11,8 +13,10 @@ interface Route extends PropsWithChildren { } const PrivateRoute = ({ children, isGuestAllowed = false, path = PATH.LOGIN }: Route) => { + const authInfo = useContext(AuthContext); const isLoggedIn = getCookieToken().accessToken; - const hasEssentialInfo = getCookieToken().hasEssentialInfo === 'true'; + const hasEssentialInfo = localStorage.getItem('hasEssentialInfo'); + // const isAuthenticated = true; if (!isGuestAllowed && !isLoggedIn) { alert('해당 페이지에 접근하려면 로그인이 필요합니다.'); @@ -28,12 +32,18 @@ const PrivateRoute = ({ children, isGuestAllowed = false, path = PATH.LOGIN }: R } */ - if (isLoggedIn && !hasEssentialInfo) { + if (isLoggedIn && hasEssentialInfo === 'false') { alert('개인정보를 먼저 등록해주세요.'); return ; } + if (isLoggedIn && hasEssentialInfo === null) { + authInfo.clearLoggedInfo(); + + return ; + } + return children; };