access_token 쿠키 확인하여 로그인 상태 유지 처리

ProtectedRoute 로 로그인 필요 페이지 접근 관리
import 문을 src/ 포함된 절대경로로 개선
This commit is contained in:
2026-01-02 11:21:56 +09:00
parent 985ba75d34
commit 767435cad4
19 changed files with 125 additions and 156 deletions

View File

@@ -0,0 +1,28 @@
import React from 'react';
import { Navigate, useLocation } from 'react-router-dom';
import { useAuth } from 'src/hooks/useAuth';
import { CSpinner } from '@coreui/react';
const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const { state } = useAuth();
const { isAuthenticated, loading } = state;
const location = useLocation();
if (loading) {
return (
<div className="pt-3 text-center">
<CSpinner color="primary" variant="grow" />
</div>
);
}
if (!isAuthenticated) {
// 로그인 되지 않았다면 로그인 페이지로 리다이렉트
// 현재 위치를 state에 저장하여 로그인 후 다시 돌아올 수 있게 함
return <Navigate to="/login" state={{ from: location }} replace />;
}
return <>{children}</>;
};
export default ProtectedRoute;

15
src/routes/routes.ts Normal file
View File

@@ -0,0 +1,15 @@
import React from 'react'
const Dashboard = React.lazy(() => import('src/views/dashboard/Dashboard'))
const Colors = React.lazy(() => import('src/views/theme/colors/Colors'))
const Typography = React.lazy(() => import('src/views/theme/typography/Typography'))
const routes = [
{ path: '/', exact: true, name: 'Home' },
{ path: '/dashboard', name: 'Dashboard', element: Dashboard },
{ path: '/theme', name: 'Theme', element: Colors, exact: true },
{ path: '/theme/colors', name: 'Colors', element: Colors },
{ path: '/theme/typography', name: 'Typography', element: Typography },
]
export default routes