2025-11-26 21:11:12 +08:00
|
|
|
import { Navigate, Outlet, useLocation } from 'react-router-dom';
|
|
|
|
|
import { useAuth } from '@/shared/context/AuthContext';
|
|
|
|
|
|
|
|
|
|
export const ProtectedRoute = () => {
|
|
|
|
|
const { isAuthenticated, isLoading } = useAuth();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return <div className="flex h-screen items-center justify-center">Loading...</div>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isAuthenticated) {
|
|
|
|
|
return <Navigate to="/login" state={{ from: location }} replace />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <Outlet />;
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-27 18:01:57 +08:00
|
|
|
|
2025-12-11 19:09:10 +08:00
|
|
|
|