import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom'; import Home from './pages/Home'; import WebLayout from "./layouts/WebLayout"; import NotFound from './pages/NotFound'; import ROUTE_CONSTANTS from './types/routes'; import Create from './pages/Create'; import Favorites from './pages/Favorites'; import Profile from './pages/Profile'; import ShoppingList from './pages/ShoppingList'; import LoginPage from './pages/Login'; import { use, type ReactNode } from 'react'; import { AuthContext } from './context/AuthContext'; import RecipePage from './pages/Recipe'; import SearchPage from './pages/Search'; function ProtectedRoute({ children }: { children: ReactNode }) { const { isLoggedIn } = use(AuthContext) // Wait until the value is set if (isLoggedIn === undefined) { // Still checking auth state: don't render anything yet, or show a spinner if desired return null; // or } if (isLoggedIn) return children; // Redirect to login page if not authenicated return } function App() { return ( } /> {/* Login page does not inherit WebLayout */} } /> }> } /> } /> } /> } /> } /> } /> } /> } /> {/* 404: Not Found */} }> } /> ); } export default App