Разработка админ-панели EventHubFrontAdmin v1.0 #1

This commit is contained in:
2026-05-23 20:43:21 +03:00
parent 36c95b71a4
commit f5961c5529
68 changed files with 10374 additions and 3 deletions
+32
View File
@@ -0,0 +1,32 @@
import React from 'react';
import { Navigate, Outlet } from 'react-router-dom';
import { Spin } from 'antd';
import { useAuthStore } from '../store/authStore';
interface Props {
allowedRoles?: string[];
}
const ProtectedRoute: React.FC<Props> = ({ allowedRoles }) => {
const { isAuthenticated, isInitialized, user } = useAuthStore();
if (!isInitialized) {
return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}>
<Spin size="large" />
</div>
);
}
if (!isAuthenticated) {
return <Navigate to="/login" replace />;
}
if (allowedRoles && user && !allowedRoles.includes(user.role)) {
return <Navigate to="/dashboard" replace />;
}
return <Outlet />;
};
export default ProtectedRoute;