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...
(wrappedComponent: React.ComponentType
) {
const Component = wrappedComponent;
return function ProtectedComponent(props: P) {
return (