From 881366e768686c3eb40d0ee49603c6d556562f1d Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Mon, 1 Sep 2025 07:33:32 +0200 Subject: [PATCH] Fix jwt-token --- client/src/components/Layout.jsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsx index d8d717e..9d7cc9a 100644 --- a/client/src/components/Layout.jsx +++ b/client/src/components/Layout.jsx @@ -35,10 +35,15 @@ const Layout = () => { const { connected, recentDetections } = useSocket(); const location = useLocation(); - // Build navigation based on user role - const navigation = user?.role === 'admin' - ? [...baseNavigation, ...adminNavigation] - : baseNavigation; + // Build navigation based on user role - ensure it's always an array + const navigation = React.useMemo(() => { + if (!user) { + return baseNavigation; // Return base navigation if user not loaded yet + } + return user.role === 'admin' + ? [...baseNavigation, ...adminNavigation] + : baseNavigation; + }, [user?.role]); return (
@@ -86,7 +91,7 @@ const Layout = () => {

- {navigation.find(item => item.href === location.pathname)?.name || 'Drone Detection System'} + {navigation?.find(item => item.href === location.pathname)?.name || 'Drone Detection System'}

@@ -166,7 +171,7 @@ const SidebarContent = () => {