From c8897ba69cf04ae540972bee64556eb2e0ae422d Mon Sep 17 00:00:00 2001 From: jessikitty Date: Tue, 27 Jan 2026 22:29:34 +1100 Subject: [PATCH] Update App.tsx with routing and authentication --- frontend/src/App.tsx | 155 ++++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 76 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index d628be3..1759338 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,83 +1,86 @@ -import { useState } from 'react' +import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom'; +import { AuthProvider, useAuth } from './contexts/AuthContext'; +import Login from './pages/Login'; +import Dashboard from './pages/Dashboard'; -function App() { - const [count, setCount] = useState(0) +// Protected route wrapper +function ProtectedRoute({ children }: { children: React.ReactNode }) { + const { user, isLoading } = useAuth(); - return ( -
-
+ if (isLoading) { + return ( +
-

- 🏠 Family Hub -

-

- Home Management System -

- -
-

Welcome!

-

- Family Hub is starting up. The backend API should be available at{' '} - - http://localhost:8000/docs - -

- -
- -
- -
-
-

✅ Phase 1 Complete:

-
    -
  • Backend API with authentication
  • -
  • Database models for users, chores, meals
  • -
  • React frontend foundation
  • -
  • Docker setup
  • -
-
- -
-

🚧 Coming Next (Phase 2):

-
    -
  • Chore management system
  • -
  • User login interface
  • -
  • Dashboard with today's tasks
  • -
  • Assignment and completion tracking
  • -
-
-
-
- -
-
-

📅 Calendar

-

Phase 3

-
-
-

🍽️ Meals

-

Phase 4

-
-
-

🏡 Home Assistant

-

Phase 6

-
-
+
+

Loading...

-
- ) + ); + } + + if (!user) { + return ; + } + + return <>{children}; } -export default App +// Public route wrapper (redirects to dashboard if already logged in) +function PublicRoute({ children }: { children: React.ReactNode }) { + const { user, isLoading } = useAuth(); + + if (isLoading) { + return ( +
+
+
+

Loading...

+
+
+ ); + } + + if (user) { + return ; + } + + return <>{children}; +} + +function App() { + return ( + + + + {/* Public routes */} + + + + } + /> + + {/* Protected routes */} + + + + } + /> + + {/* Default route */} + } /> + + {/* 404 catch-all */} + } /> + + + + ); +} + +export default App;