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...
-Authentication Error
-Please log in again
- -+ {loading ? 'Loading dashboard...' : 'Redirecting...'} +