Skip to content

Commit

Permalink
fix: (#516) hasEssentialInfo 정보를 삭제했을 때 개인 정보를 다시 입력할 수 있던 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilpop8663 committed Sep 4, 2023
1 parent ce217d4 commit f6d405f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions frontend/src/routes/PrivateRoute.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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('해당 페이지에 접근하려면 로그인이 필요합니다.');
Expand All @@ -28,12 +32,18 @@ const PrivateRoute = ({ children, isGuestAllowed = false, path = PATH.LOGIN }: R
}
*/

if (isLoggedIn && !hasEssentialInfo) {
if (isLoggedIn && hasEssentialInfo === 'false') {
alert('개인정보를 먼저 등록해주세요.');

return <Navigate to={PATH.USER_INFO_REGISTER} />;
}

if (isLoggedIn && hasEssentialInfo === null) {
authInfo.clearLoggedInfo();

return <Navigate to="/" />;
}

return children;
};

Expand Down

0 comments on commit f6d405f

Please sign in to comment.