import React, { useState, useEffect } from 'react'; import { HashRouter as Router, Routes, Route, Navigate, useLocation } from 'react-router-dom'; import { Layout } from './components/Layout'; import { Dashboard } from './pages/Dashboard'; import { UserDetail } from './pages/UserDetail'; import { AttendanceDetail } from './pages/AttendanceDetail'; import { SuperAdmin } from './pages/SuperAdmin'; import { TeamManagement } from './pages/TeamManagement'; import { Login } from './pages/Login'; import { UserProfile } from './pages/UserProfile'; import { getUserById } from './services/dataService'; import { User } from './types'; const AuthGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); const location = useLocation(); useEffect(() => { const checkAuth = async () => { const storedUserId = localStorage.getItem('ctms_user_id'); if (!storedUserId) { setLoading(false); return; } try { const fetchedUser = await getUserById(storedUserId); if (fetchedUser) { setUser(fetchedUser); } else { localStorage.removeItem('ctms_user_id'); } } catch (err) { console.error("Auth check failed", err); } finally { setLoading(false); } }; checkAuth(); }, [location.pathname]); if (loading) { return
Carregando...
; } if (!user) { return ; } return {children}; }; const App: React.FC = () => { return ( } /> } /> } /> } /> } /> } /> } /> } /> ); }; export default App;