diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index d32919b..f7914c0 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -4,7 +4,7 @@ import React, { useState, useEffect, useTransition, useCallback, lazy } from 'react'; import { useQueryClient } from '@tanstack/react-query'; -import { Routes, Route, Navigate } from 'react-router-dom'; +import { Routes, Route, Navigate, useLocation } from 'react-router-dom'; import { useAuth0 } from '@auth0/auth0-react'; import { useIsAuthInitialized } from './core/auth/auth-gate'; import { motion, AnimatePresence } from 'framer-motion'; @@ -238,6 +238,7 @@ const AddVehicleScreen: React.FC = ({ onBack, onAdded }) function App() { const { isLoading, isAuthenticated, user } = useAuth0(); + const location = useLocation(); const isAuthGateReady = useIsAuthInitialized(); const [_isPending, startTransition] = useTransition(); console.log('[DEBUG App] Render check - isLoading:', isLoading, 'isAuthenticated:', isAuthenticated, 'isAuthGateReady:', isAuthGateReady); @@ -363,6 +364,10 @@ function App() { console.log('MotoVaultPro status:', { isLoading, isAuthenticated, mobileMode, activeScreen, vehicleSubScreen, userAgent: navigator.userAgent }); + const isGarageRoute = location.pathname === '/garage' || location.pathname.startsWith('/garage/'); + const isCallbackRoute = location.pathname === '/callback'; + const shouldShowHomePage = !isGarageRoute && !isCallbackRoute; + // Enhanced navigation handlers for mobile const handleVehicleSelect = useCallback((vehicle: Vehicle) => { setSelectedVehicle(vehicle); @@ -416,7 +421,18 @@ function App() { ); } - if (!isAuthenticated) { + if (isCallbackRoute) { + return ( + + +
+
Processing login...
+
+
+ ); + } + + if (shouldShowHomePage) { return ( @@ -426,6 +442,10 @@ function App() { ); } + if (!isAuthenticated) { + return ; + } + // Wait for auth gate to be ready before rendering protected routes // This prevents a race condition where the page renders before the auth token is ready if (!isAuthGateReady) { @@ -615,17 +635,16 @@ function App() { - } /> - Processing login...} /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index b7bac6a..cba5356 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -37,12 +37,12 @@ export const Layout: React.FC = ({ children, mobileMode = false }) }, [mobileMode, setSidebarOpen]); // Removed sidebarOpen from dependencies const navigation = [ - { name: 'Vehicles', href: '/vehicles', icon: }, - { name: 'Fuel Logs', href: '/fuel-logs', icon: }, - { name: 'Maintenance', href: '/maintenance', icon: }, - { name: 'Gas Stations', href: '/stations', icon: }, - { name: 'Documents', href: '/documents', icon: }, - { name: 'Settings', href: '/settings', icon: }, + { name: 'Vehicles', href: '/garage/vehicles', icon: }, + { name: 'Fuel Logs', href: '/garage/fuel-logs', icon: }, + { name: 'Maintenance', href: '/garage/maintenance', icon: }, + { name: 'Gas Stations', href: '/garage/stations', icon: }, + { name: 'Documents', href: '/garage/documents', icon: }, + { name: 'Settings', href: '/garage/settings', icon: }, ]; // Mobile layout diff --git a/frontend/src/core/auth/Auth0Provider.tsx b/frontend/src/core/auth/Auth0Provider.tsx index 1dd427d..7657762 100644 --- a/frontend/src/core/auth/Auth0Provider.tsx +++ b/frontend/src/core/auth/Auth0Provider.tsx @@ -26,7 +26,8 @@ export const Auth0Provider: React.FC = ({ children }) => { const onRedirectCallback = (appState?: { returnTo?: string }) => { console.log('[Auth0Provider] Redirect callback triggered', { appState, returnTo: appState?.returnTo }); - navigate(appState?.returnTo || '/dashboard'); + const target = appState?.returnTo || '/garage'; + navigate(target, { replace: true }); }; return ( diff --git a/frontend/src/features/documents/mobile/DocumentsMobileScreen.test.tsx b/frontend/src/features/documents/mobile/DocumentsMobileScreen.test.tsx index c35c693..a3f790d 100644 --- a/frontend/src/features/documents/mobile/DocumentsMobileScreen.test.tsx +++ b/frontend/src/features/documents/mobile/DocumentsMobileScreen.test.tsx @@ -187,7 +187,7 @@ describe('DocumentsMobileScreen', () => { const openButtons = screen.getAllByText('Open'); await user.click(openButtons[0]); - expect(mockNavigate).toHaveBeenCalledWith('/documents/doc-1'); + expect(mockNavigate).toHaveBeenCalledWith('/garage/documents/doc-1'); }); it('should navigate to correct document for each Open button', async () => { @@ -197,10 +197,10 @@ describe('DocumentsMobileScreen', () => { const openButtons = screen.getAllByText('Open'); await user.click(openButtons[0]); - expect(mockNavigate).toHaveBeenCalledWith('/documents/doc-1'); + expect(mockNavigate).toHaveBeenCalledWith('/garage/documents/doc-1'); await user.click(openButtons[1]); - expect(mockNavigate).toHaveBeenCalledWith('/documents/doc-2'); + expect(mockNavigate).toHaveBeenCalledWith('/garage/documents/doc-2'); }); }); @@ -406,4 +406,4 @@ describe('DocumentsMobileScreen', () => { expect(uploadButtons).toHaveLength(mockDocuments.length); }); }); -}); \ No newline at end of file +}); diff --git a/frontend/src/features/documents/mobile/DocumentsMobileScreen.tsx b/frontend/src/features/documents/mobile/DocumentsMobileScreen.tsx index cd96e6d..c9208e1 100644 --- a/frontend/src/features/documents/mobile/DocumentsMobileScreen.tsx +++ b/frontend/src/features/documents/mobile/DocumentsMobileScreen.tsx @@ -185,7 +185,7 @@ export const DocumentsMobileScreen: React.FC = () => {
{doc.document_type} • {vehicleLabel}
- + {upload.isPending && currentId === doc.id && ( {upload.progress}% diff --git a/frontend/src/features/documents/pages/DocumentDetailPage.tsx b/frontend/src/features/documents/pages/DocumentDetailPage.tsx index e9fd364..593c1b0 100644 --- a/frontend/src/features/documents/pages/DocumentDetailPage.tsx +++ b/frontend/src/features/documents/pages/DocumentDetailPage.tsx @@ -64,7 +64,7 @@ export const DocumentDetailPage: React.FC = () => {

Please log in to view this document

- +
@@ -88,7 +88,7 @@ export const DocumentDetailPage: React.FC = () => {

Your session has expired. Please log in again to continue.

- +
@@ -112,7 +112,7 @@ export const DocumentDetailPage: React.FC = () => {

The document you're looking for could not be found.

- +
@@ -127,7 +127,7 @@ export const DocumentDetailPage: React.FC = () => {

Document Not Found

The document you're looking for does not exist.

- +
diff --git a/frontend/src/features/documents/pages/DocumentsPage.tsx b/frontend/src/features/documents/pages/DocumentsPage.tsx index 4f957d4..54b0daa 100644 --- a/frontend/src/features/documents/pages/DocumentsPage.tsx +++ b/frontend/src/features/documents/pages/DocumentsPage.tsx @@ -115,7 +115,7 @@ export const DocumentsPage: React.FC = () => {

No Documents Yet

You haven't added any documents yet. Documents will appear here once you create them.

- @@ -131,7 +131,7 @@ export const DocumentsPage: React.FC = () => {
Type: {doc.document_type}
Vehicle: {doc.vehicle_id}
- +
diff --git a/frontend/src/features/vehicles/pages/VehicleDetailPage.tsx b/frontend/src/features/vehicles/pages/VehicleDetailPage.tsx index 73f7436..db07ac8 100644 --- a/frontend/src/features/vehicles/pages/VehicleDetailPage.tsx +++ b/frontend/src/features/vehicles/pages/VehicleDetailPage.tsx @@ -129,7 +129,7 @@ export const VehicleDetailPage: React.FC = () => { }, [id]); const handleBack = () => { - navigate('/vehicles'); + navigate('/garage/vehicles'); }; const handleEdit = () => { diff --git a/frontend/src/features/vehicles/pages/VehiclesPage.tsx b/frontend/src/features/vehicles/pages/VehiclesPage.tsx index 7f3654e..75585fe 100644 --- a/frontend/src/features/vehicles/pages/VehiclesPage.tsx +++ b/frontend/src/features/vehicles/pages/VehiclesPage.tsx @@ -53,7 +53,7 @@ export const VehiclesPage: React.FC = () => { startTransition(() => { const vehicle = optimisticVehicles.find(v => v.id === id); setSelectedVehicle(vehicle || null); - navigate(`/vehicles/${id}`); + navigate(`/garage/vehicles/${id}`); }); }; @@ -191,4 +191,4 @@ export const VehiclesPage: React.FC = () => { ); -}; \ No newline at end of file +}; diff --git a/frontend/src/pages/HomePage.tsx b/frontend/src/pages/HomePage.tsx index 4ef4ff2..36e6be9 100644 --- a/frontend/src/pages/HomePage.tsx +++ b/frontend/src/pages/HomePage.tsx @@ -1,15 +1,22 @@ import { useState } from 'react'; import { useAuth0 } from '@auth0/auth0-react'; +import { useNavigate } from 'react-router-dom'; import { HeroCarousel } from './HomePage/HeroCarousel'; import { FeaturesGrid } from './HomePage/FeaturesGrid'; import { motion } from 'framer-motion'; export const HomePage = () => { - const { loginWithRedirect } = useAuth0(); + const { loginWithRedirect, isAuthenticated } = useAuth0(); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); + const navigate = useNavigate(); - const handleGetStarted = () => { - loginWithRedirect(); + const handleAuthAction = () => { + if (isAuthenticated) { + navigate('/garage'); + return; + } + + loginWithRedirect({ appState: { returnTo: '/garage' } }); }; return ( @@ -38,10 +45,10 @@ export const HomePage = () => { About @@ -97,10 +104,10 @@ export const HomePage = () => { About )} @@ -133,7 +140,7 @@ export const HomePage = () => { your needs.