diff --git a/frontend/src/components/NotificationBell.jsx b/frontend/src/components/NotificationBell.jsx index f25cc29..7ab893f 100644 --- a/frontend/src/components/NotificationBell.jsx +++ b/frontend/src/components/NotificationBell.jsx @@ -41,7 +41,13 @@ function NotificationBell({ onShowToast }) { setNotifications(data); setUnreadCount(data.filter((n) => !n.is_read).length); } catch (error) { - // Silent fail for polling + // If unauthorized (401), user is not logged in - don't show errors + if (error.message.includes("401") || error.message.includes("Unauthorized") || error.message.includes("User not found")) { + setNotifications([]); + setUnreadCount(0); + return; + } + // Silent fail for other polling errors console.error("Failed to load notifications", error); } }; diff --git a/frontend/src/notificationApi.js b/frontend/src/notificationApi.js index 6ae055a..295ae86 100644 --- a/frontend/src/notificationApi.js +++ b/frontend/src/notificationApi.js @@ -16,6 +16,9 @@ export async function getNotifications(unreadOnly = false) { }); if (!response.ok) { + if (response.status === 401) { + throw new Error("Unauthorized"); + } const errorData = await response.json().catch(() => ({ detail: "Failed to fetch notifications" })); throw new Error(errorData.detail || "Failed to fetch notifications"); }