import React from 'react' import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom' import { Toaster } from 'sonner' import Layout from '@/components/layout/Layout' import Dashboard from '@/pages/Dashboard' import Search from '@/pages/Search' import MultiSearch from '@/pages/MultiSearch' import AmazonSearch from '@/pages/AmazonSearch' import Catalogues from '@/pages/Catalogues' import Login from '@/pages/Login' import Admin from '@/pages/Admin' import { useTheme } from '@/hooks/use-theme' import { AuthProvider, useAuth } from '@/hooks/use-auth' // Protected route wrapper function ProtectedRoute({ children, adminOnly = false }) { const { isAuthenticated, isAdmin, loading } = useAuth(); if (loading) { return (
); } if (!isAuthenticated) { return ; } if (adminOnly && !isAdmin) { return ; } return children; } // Public route that redirects to home if already logged in function PublicRoute({ children }) { const { isAuthenticated, loading } = useAuth(); if (loading) { return (
); } if (isAuthenticated) { return ; } return children; } function AppRoutes() { const { theme, toggleTheme } = useTheme(); const { isAuthenticated } = useAuth(); return ( <> } /> } /> } /> } /> } /> } /> } /> } /> ); } export default function App() { return ( ); }