import { useEffect, type ReactNode } from 'react'; import { Navigate, Route, Routes, useLocation } from 'react-router-dom'; import { useAuth } from '@/stores/auth'; import { useChat } from '@/stores/chat'; import { AppShell } from '@/components/layout/app-shell'; import { ChatView } from '@/components/chat/chat-view'; import { LoginPage } from '@/features/auth/login-page'; import { PrivacyPage } from '@/features/auth/privacy-page'; import { SetPasswordPage } from '@/features/auth/set-password-page'; import { ProfessorPage } from '@/features/professor/professor-page'; import { AdminCostsPage } from '@/features/professor/admin-costs-page'; import { Spinner } from '@/components/ui/spinner'; function Guard({ children, role }: { children: ReactNode; role?: 'professor' | 'admin' }) { const { user, loading } = useAuth(); const loc = useLocation(); if (loading) return
; if (!user) return ; if (role === 'professor' && !(user.role === 'professor' || user.role === 'admin')) return ; if (role === 'admin' && user.role !== 'admin') return ; return <>{children}; } export function AppRouter() { const { user, load } = useAuth(); const loadConversations = useChat((s) => s.loadConversations); useEffect(() => { load(); }, [load]); useEffect(() => { if (user) loadConversations().catch(() => undefined); }, [user, loadConversations]); return ( } /> } /> } /> } /> } /> }> } /> } /> } /> ); }