23 lines
638 B
React
23 lines
638 B
React
|
|
import { Navigate } from 'react-router-dom';
|
||
|
|
import { useAuth } from '../context/AuthContext';
|
||
|
|
|
||
|
|
const PrivateRoute = ({ children }) => {
|
||
|
|
const { admin, loading } = useAuth();
|
||
|
|
|
||
|
|
if (loading) {
|
||
|
|
return (
|
||
|
|
<div className="min-h-screen flex items-center justify-center">
|
||
|
|
<div className="text-center">
|
||
|
|
<div className="w-16 h-16 border-4 border-primary-500 border-t-transparent rounded-full animate-spin mx-auto"></div>
|
||
|
|
<p className="mt-4 text-gray-600">Loading...</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
return admin ? children : <Navigate to="/login" replace />;
|
||
|
|
};
|
||
|
|
|
||
|
|
export default PrivateRoute;
|
||
|
|
|