import { type ReactNode } from 'react'; import { motion } from 'framer-motion'; import { ShieldAlert, LogIn, Sparkles, ShieldCheck } from 'lucide-react'; import { useAuth } from '@/context/AuthContext'; interface ProtectedRouteProps { children: ReactNode; title: string; description: string; requireVerifiedStudent?: boolean; } export default function ProtectedRoute({ children, title, description, requireVerifiedStudent = false, }: ProtectedRouteProps) { const { isAuthenticated, isVerifiedStudent, loginWithGoogle, user } = useAuth(); // If user is authenticated (and meets verified student criteria if required), render the actual page! const isAllowed = isAuthenticated && (!requireVerifiedStudent || isVerifiedStudent); if (isAllowed) { return <>{children}>; } return (
{!isAuthenticated ? ( <> {description} Sign in with your Google account to access this feature. > ) : ( <> You are signed in as {user?.email}. This feature is restricted to verified students with an @ritchennai.edu.in college email. > )}
{/* Action Button */}Sign-in is quick, secure, and preserves your student privacy.