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; };