'use client'; import { useRouter } from 'next/navigation'; import { useEffect, useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { getCurrentUser } from '@/lib/api'; import { ShieldCheck, Fingerprint, Globe, Cpu, Lock } from 'lucide-react'; interface ProtectedRouteProps { children: React.ReactNode; fallback?: React.ReactNode; } export default function ProtectedRoute({ children, fallback }: ProtectedRouteProps) { const [isAuthenticated, setIsAuthenticated] = useState(null); const router = useRouter(); useEffect(() => { const checkAuthStatus = async () => { try { const user = await getCurrentUser(); if (user) { setIsAuthenticated(true); } else { setIsAuthenticated(false); setTimeout(() => { try { router.replace('/login'); } catch (error) { window.location.href = '/login'; } }, 300); } } catch (error) { const storedUser = localStorage.getItem('user'); if (storedUser) { setIsAuthenticated(true); } else { setIsAuthenticated(false); setTimeout(() => { try { router.replace('/login'); } catch (error) { window.location.href = '/login'; } }, 300); } } }; const timer = setTimeout(checkAuthStatus, 200); return () => clearTimeout(timer); }, [router]); if (isAuthenticated === null) { return (
{/* Dynamic Background Elements */}
{/* Central Logo/Icon Animation */}
{/* Spinning Rings */}
{/* Status Text */}

Neural Handshake

{[0, 1, 2].map((i) => ( ))}
Verifying Identity Matrix
{/* Feature Grid (Subtle) */}
{[ { icon: ShieldCheck, label: "Secure" }, { icon: Globe, label: "Global" }, { icon: Lock, label: "Encrypted" } ].map((item, i) => ( {item.label} ))}
{/* Binary Stream Decoration */}
{[0, 1, 0, 1, 1, 0].map((v, i) => ( {v} ))}
{[1, 0, 1, 0, 0, 1].map((v, i) => ( {v} ))}
); } if (isAuthenticated) { return <>{children}; } return null; }