diff --git a/frontend/src/App.js b/frontend/src/App.js index af5c374..a8e2327 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -11,6 +11,7 @@ import Expenses from './pages/Expenses'; import Users from './pages/Users'; import Dashboard from './pages/Dashboard'; import ProtectedRoute from './components/ProtectedRoute'; +import GuestRoute from './components/GuestRoute'; import ForgotPassword from './pages/ForgotPassword'; import NotFound from './pages/NotFound'; import { ThemeProvider, CssBaseline, Box } from '@mui/material'; @@ -43,8 +44,22 @@ function App() { } /> - } /> - } /> + + + + } + /> + + + + } + /> } /> - } /> + + + + } + /> } /> diff --git a/frontend/src/components/GuestRoute.js b/frontend/src/components/GuestRoute.js new file mode 100644 index 0000000..febf1e4 --- /dev/null +++ b/frontend/src/components/GuestRoute.js @@ -0,0 +1,12 @@ +import React from 'react'; +import { Navigate } from 'react-router-dom'; +import { isLoggedIn } from '../services/auth'; + +function GuestRoute({ children, redirectTo = '/' }) { + if (isLoggedIn()) { + return ; + } + return children; +} + +export default GuestRoute; diff --git a/frontend/src/components/LoadingOverlay.js b/frontend/src/components/LoadingOverlay.js index 5b3c3c8..138fa3c 100644 --- a/frontend/src/components/LoadingOverlay.js +++ b/frontend/src/components/LoadingOverlay.js @@ -5,7 +5,8 @@ import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; // Render free-tier specs — surface a friendly note when a request hangs long // enough that the user might think the app is broken. Numbers come from // Render's published free-instance limits (see README "Live API" section). -const FREE_TIER_INFO = "We're on Render's free tier (0.1 CPU / 512 MB RAM). When the service has been idle, the first request triggers a cold start that usually takes 30–60 seconds. Subsequent requests are fast."; +const FREE_TIER_INFO = + "We're on Render's free tier (0.1 CPU / 512 MB RAM). When the service has been idle, the first request triggers a cold start that usually takes 30–60 seconds. Subsequent requests are fast."; const LONG_LOAD_MS = 4000; const COLD_START_MS = 10000; @@ -35,12 +36,7 @@ function LoadingOverlay({ loading, longLoadMs = LONG_LOAD_MS, coldStartMs = COLD if (!loading) return null; - const message = - stage === 'cold' - ? 'Still waking up the server…' - : stage === 'slow' - ? 'Render is taking a while to load up…' - : 'Loading data…'; + const message = stage === 'cold' ? 'Still waking up the server…' : stage === 'slow' ? 'Render is taking a while to load up…' : 'Loading data…'; return ( - {stage === 'cold' - ? `Hang tight — the backend may be cold-starting (${elapsed}s elapsed).` - : 'First request after idle can be slow.'} + {stage === 'cold' ? `Hang tight — the backend may be cold-starting (${elapsed}s elapsed).` : 'First request after idle can be slow.'} - +