29 lines
698 B
TypeScript
29 lines
698 B
TypeScript
|
|
import { Navigate, Outlet } from 'react-router';
|
||
|
|
import { useAuth } from './useAuth';
|
||
|
|
|
||
|
|
export function ProtectedRoute() {
|
||
|
|
const { user, loading } = useAuth();
|
||
|
|
|
||
|
|
if (loading) {
|
||
|
|
return (
|
||
|
|
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
||
|
|
<div className="animate-spin h-8 w-8 border-4 border-blue-500 border-t-transparent rounded-full" />
|
||
|
|
</div>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!user) {
|
||
|
|
return <Navigate to="/login" replace />;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (user.status === 'PENDING') {
|
||
|
|
return <Navigate to="/pending" replace />;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (user.status === 'REJECTED' || user.status === 'DISABLED') {
|
||
|
|
return <Navigate to="/denied" replace />;
|
||
|
|
}
|
||
|
|
|
||
|
|
return <Outlet />;
|
||
|
|
}
|