import React from 'react'
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'
import { AuthProvider, useAuth } from './context/AuthContext'
import LoginPage from './pages/LoginPage'
import Dashboard from './pages/Dashboard'
// Protected Route Component
function ProtectedRoute({ children }) {
const { isAuthenticated, loading } = useAuth()
if (loading) {
return (
)
}
return isAuthenticated ? children :
}
// Public Route Component (redirect to dashboard if already logged in)
function PublicRoute({ children }) {
const { isAuthenticated, loading } = useAuth()
if (loading) {
return (
)
}
return !isAuthenticated ? children :
}
function AppRoutes() {
return (
{/* Public Routes */}
}
/>
{/* Protected Routes */}
}
/>
{/* Catch all - redirect to dashboard or login */}
} />
)
}
function App() {
return (
)
}
export default App