import { useContext, useEffect } from "react"; import { BrowserRouter as Router, Routes, Route, Navigate } from "react-router-dom"; import GlobalStateContext from "./Contexts/GlobalStateContext"; import DefaultLayout from "./Layouts/DefaultLayout"; import Login from "./Pages/Login"; import { RouteLink } from "./Routes/Routes"; function App() { const context = useContext(GlobalStateContext); if (!context) throw new Error("App must be used within a GlobalStateProvider"); const { isAuthenticate, setIsAuthenticate } = context; useEffect(() => { const token = localStorage.getItem("token"); setIsAuthenticate(!!token); // Converts token to boolean }, [setIsAuthenticate]); console.log("Auth Status:", isAuthenticate); return ( {/* Redirect logged-in users away from login */} : } /> {/* Protected Routes */} {RouteLink.map(({ path, Component }, index) => ( } /> ))} ) : ( )} /> {/* Catch-all route to prevent unauthorized access */} } /> ); } export default App;