2026-04-04 21:48:56 +02:00
|
|
|
import { Navigate } from 'react-router';
|
2026-04-05 01:17:47 +02:00
|
|
|
import { useLogto } from '@logto/react';
|
|
|
|
|
import { Spinner } from '@cameleer/design-system';
|
2026-04-04 21:48:56 +02:00
|
|
|
|
|
|
|
|
export function ProtectedRoute({ children }: { children: React.ReactNode }) {
|
2026-04-05 01:17:47 +02:00
|
|
|
const { isAuthenticated, isLoading } = useLogto();
|
|
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return (
|
|
|
|
|
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: '100vh' }}>
|
|
|
|
|
<Spinner />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-04 21:48:56 +02:00
|
|
|
if (!isAuthenticated) return <Navigate to="/login" replace />;
|
|
|
|
|
return <>{children}</>;
|
|
|
|
|
}
|