From 17b64121db8792ee38546ef4778ada27e5d0e01d Mon Sep 17 00:00:00 2001 From: IluaAir Date: Tue, 21 Oct 2025 22:29:56 +0300 Subject: [PATCH] Enhance Dashboard component to redirect on authentication error and streamline loading state display --- taskncoffee-app/src/pages/Dashboard.jsx | 41 ++++++++----------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/taskncoffee-app/src/pages/Dashboard.jsx b/taskncoffee-app/src/pages/Dashboard.jsx index 0eac2d8..b554f99 100644 --- a/taskncoffee-app/src/pages/Dashboard.jsx +++ b/taskncoffee-app/src/pages/Dashboard.jsx @@ -7,6 +7,7 @@ import { Home, Settings, Bell } from 'lucide-react'; import { Avatar, AvatarImage, AvatarFallback } from '@/components/ui/avatar'; import { jwtexp } from '@/lib/utils'; import Calendar from '@/components/Calendar'; +import { useNavigate } from "react-router"; const menuItems = [ { label: 'home', icon: Home, onClick: () => console.log('Home clicked') }, @@ -15,6 +16,7 @@ const menuItems = [ ]; export default function Dashboard() { + const navigate = useNavigate(); const [loading, setLoading] = useState(true); const [authError, setAuthError] = useState(false); @@ -52,40 +54,23 @@ export default function Dashboard() { validateAuth(); }, []); - // Get current date and week - - - // Calculate the Monday of current week - - // Group tasks by day + // Redirect to login if authentication fails + useEffect(() => { + if (authError) { + console.log('Authentication error detected, redirecting to login...'); + navigate('/'); + } + }, [authError, navigate]); - - if (loading) { + if (loading || authError) { return (
-

Loading dashboard...

-
-
- ); - } - - if (authError) { - return ( -
-
-
-

Authentication Error

-

Please log in again

- -
+

+ {loading ? 'Loading dashboard...' : 'Redirecting...'} +

);