1- import React from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import { BrowserRouter , Route , Routes , Navigate } from 'react-router-dom' ;
33
44import Home from '@pages/Home' ;
@@ -7,6 +7,7 @@ import LoginComplete from '@pages/Login/LoginComplete';
77
88import SignUp from '@pages/SignUp' ;
99import TermsAgreement from '@pages/SignUp/TermsAgreement' ;
10+ import PickMyStyle from '@pages/SignUp/PickMyStyle' ;
1011
1112import Profile from '@pages/Profile' ;
1213import ProfileEdit from '@pages/Profile/ProfileEdit' ;
@@ -24,11 +25,29 @@ import PostInstaFeedSelect from '@pages/Post/PostInstaFeedSelect';
2425
2526import Chats from '@pages/Chats' ;
2627import ChatRoom from '@pages/Chats/ChatRoom' ;
28+ import MatchingRoom from '@pages/Chats/MatchingRoom' ;
2729
2830import NotFound from '@pages/NotFound' ;
31+ import { getUserInfoApi } from '@apis/user' ;
32+ import { getCurrentUserId } from '@utils/getCurrentUserId' ;
33+ import Loading from '@components/Loading' ;
2934
3035const ProtectedRoute = ( { children } : { children : JSX . Element } ) => {
31- const isAuthenticated = Boolean ( localStorage . getItem ( 'new_jwt_token' ) ) ;
36+ const [ isAuthenticated , setIsAuthenticated ] = useState < boolean | null > ( null ) ;
37+
38+ useEffect ( ( ) => {
39+ const checkAuth = async ( ) => {
40+ const currentUserId = getCurrentUserId ( ) ;
41+ const response = await getUserInfoApi ( currentUserId ) ;
42+ setIsAuthenticated ( response . isSuccess ) ;
43+ } ;
44+ checkAuth ( ) ;
45+ } , [ ] ) ;
46+
47+ if ( isAuthenticated === null ) {
48+ return < Loading /> ;
49+ }
50+
3251 return isAuthenticated ? children : < Navigate to = "/login" /> ;
3352} ;
3453
@@ -55,6 +74,7 @@ const protectedRoutes = [
5574 // 메시지/채팅
5675 { path : '/chats' , element : < Chats /> } ,
5776 { path : '/chats/:chatRoomId' , element : < ChatRoom /> } ,
77+ { path : '/matching' , element : < MatchingRoom /> } ,
5878] ;
5979
6080// 인증이 필요 없는 페이지 배열
@@ -64,6 +84,7 @@ const publicRoutes = [
6484
6585 { path : '/signup' , element : < SignUp /> } ,
6686 { path : '/signup/terms-agreement' , element : < TermsAgreement /> } ,
87+ { path : '/signup/pick-my-style' , element : < PickMyStyle /> } ,
6788] ;
6889
6990const App : React . FC = ( ) => {
0 commit comments