first commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { Navigate, useLocation } from 'react-router-dom';
|
||||
import { useAtom } from 'jotai';
|
||||
import { isAuthenticatedAtom } from '@/atoms/auth';
|
||||
import { isSupabaseConfigured } from '@/services/supabase';
|
||||
|
||||
interface ProtectedRouteProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function ProtectedRoute({ children }: ProtectedRouteProps) {
|
||||
const [isAuthenticated] = useAtom(isAuthenticatedAtom);
|
||||
const location = useLocation();
|
||||
|
||||
// In offline mode, allow access without authentication
|
||||
if (!isSupabaseConfigured) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" state={{ from: location }} replace />;
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user