Initial commit: Базовая структура сайта
This commit is contained in:
20
frontend/src/components/ProtectedRoute.jsx
Executable file
20
frontend/src/components/ProtectedRoute.jsx
Executable file
@@ -0,0 +1,20 @@
|
||||
import React from 'react'
|
||||
import { Navigate, Outlet } from 'react-router-dom'
|
||||
import { useAuth } from '../contexts/AuthContext'
|
||||
|
||||
const ProtectedRoute = ({ children }) => {
|
||||
const { isAuthenticated, loading } = useAuth()
|
||||
|
||||
if (loading) {
|
||||
return <div>Загрузка...</div>
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" replace />
|
||||
}
|
||||
|
||||
return children || <Outlet />
|
||||
}
|
||||
|
||||
export default ProtectedRoute
|
||||
|
||||
Reference in New Issue
Block a user