Skip to content

Commit 4b7938d

Browse files
committed
fix: 인증이 필요한 페이지에서 사용자 인증 로직 수정
1 parent e840ad3 commit 4b7938d

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/App.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom';
33

44
import Home from '@pages/Home';
@@ -28,9 +28,21 @@ import ChatRoom from '@pages/Chats/ChatRoom';
2828
import MatchingRoom from '@pages/Chats/MatchingRoom';
2929

3030
import NotFound from '@pages/NotFound';
31+
import { getUserInfoApi } from '@apis/user';
32+
import { getCurrentUserId } from '@utils/getCurrentUserId';
3133

3234
const ProtectedRoute = ({ children }: { children: JSX.Element }) => {
33-
const isAuthenticated = Boolean(localStorage.getItem('new_jwt_token'));
35+
const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
36+
37+
useEffect(() => {
38+
const checkAuth = async () => {
39+
const currentUserId = getCurrentUserId();
40+
const response = await getUserInfoApi(currentUserId);
41+
setIsAuthenticated(response.isSuccess);
42+
};
43+
checkAuth();
44+
}, []);
45+
3446
return isAuthenticated ? children : <Navigate to="/login" />;
3547
};
3648

0 commit comments

Comments
 (0)