import { useEffect } from 'react'; import { useNavigate } from '@remix-run/react'; import { useStore } from '@nanostores/react'; import { authStore } from '~/lib/stores/auth'; import { motion } from 'framer-motion'; interface ProtectedRouteProps { children: React.ReactNode; } export function ProtectedRoute({ children }: ProtectedRouteProps) { const navigate = useNavigate(); const authState = useStore(authStore); useEffect(() => { // If not loading and not authenticated, redirect to auth page if (!authState.loading && !authState.isAuthenticated) { navigate('/auth'); } }, [authState.loading, authState.isAuthenticated, navigate]); // Show loading state if (authState.loading) { return (

Loading your workspace...

); } // If not authenticated, don't render children (will redirect) if (!authState.isAuthenticated) { return null; } // Render protected content return <>{children}; } // HOC for protecting pages export function withAuth

(wrappedComponent: React.ComponentType

) { const Component = wrappedComponent; return function ProtectedComponent(props: P) { return ( ); }; }