Vibed it... :(

This commit is contained in:
2025-08-09 14:34:48 +01:00
commit 5cf478feab
41 changed files with 23512 additions and 0 deletions

79
frontend/src/App.tsx Normal file
View File

@@ -0,0 +1,79 @@
import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { AuthProvider, useAuth } from './context/AuthContext';
import Dashboard from './pages/Dashboard';
import Login from './pages/Login';
import Register from './pages/Register';
import './App.css';
// Protected Route component
const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const { user, loading } = useAuth();
if (loading) {
return (
<div className="loading-container">
<div className="loading-spinner"></div>
<p>Loading...</p>
</div>
);
}
return user ? <>{children}</> : <Navigate to="/login" />;
};
// Public Route component (redirect to dashboard if already logged in)
const PublicRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const { user, loading } = useAuth();
if (loading) {
return (
<div className="loading-container">
<div className="loading-spinner"></div>
<p>Loading...</p>
</div>
);
}
return user ? <Navigate to="/" /> : <>{children}</>;
};
function App() {
return (
<AuthProvider>
<Router>
<div className="App">
<Routes>
<Route
path="/"
element={
<ProtectedRoute>
<Dashboard />
</ProtectedRoute>
}
/>
<Route
path="/login"
element={
<PublicRoute>
<Login />
</PublicRoute>
}
/>
<Route
path="/register"
element={
<PublicRoute>
<Register />
</PublicRoute>
}
/>
<Route path="*" element={<Navigate to="/" />} />
</Routes>
</div>
</Router>
</AuthProvider>
);
}
export default App;