From 4add41293b82498896b16e965c32c113380ee9f6 Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Fri, 13 Feb 2026 10:01:32 +0100 Subject: [PATCH] fix: ensure safe handling of organizations and notifications data in LayoutContent and NotificationCenter components --- app/layout-content.tsx | 2 +- .../notifications/NotificationCenter.tsx | 10 +- package-lock.json | 759 +++++++++++++++++- 3 files changed, 741 insertions(+), 30 deletions(-) diff --git a/app/layout-content.tsx b/app/layout-content.tsx index 9dffd9d..1f50e03 100644 --- a/app/layout-content.tsx +++ b/app/layout-content.tsx @@ -22,7 +22,7 @@ export default function LayoutContent({ children }: { children: React.ReactNode useEffect(() => { if (auth.user) { getUserOrganizations() - .then((organizations) => setOrgs(organizations)) + .then((organizations) => setOrgs(Array.isArray(organizations) ? organizations : [])) .catch(err => console.error('Failed to fetch orgs for header', err)) } }, [auth.user]) diff --git a/components/notifications/NotificationCenter.tsx b/components/notifications/NotificationCenter.tsx index 9542723..5f66a37 100644 --- a/components/notifications/NotificationCenter.tsx +++ b/components/notifications/NotificationCenter.tsx @@ -65,8 +65,8 @@ export default function NotificationCenter() { setError(null) try { const res = await listNotifications() - setNotifications(res.notifications) - setUnreadCount(res.unread_count) + setNotifications(Array.isArray(res?.notifications) ? res.notifications : []) + setUnreadCount(typeof res?.unread_count === 'number' ? res.unread_count : 0) } catch (err) { setError(getAuthErrorMessage(err as Error) || 'Failed to load notifications') setNotifications([]) @@ -160,14 +160,14 @@ export default function NotificationCenter() { {error && (
{error}
)} - {!loading && !error && notifications.length === 0 && ( + {!loading && !error && (notifications?.length ?? 0) === 0 && (
No notifications yet
)} - {!loading && !error && notifications.length > 0 && ( + {!loading && !error && (notifications?.length ?? 0) > 0 && (