Enhance NotificationProvider to fetch notifications based on authentication and token presence, improving notification handling logic.

This commit is contained in:
Tom Butcher 2026-06-21 19:42:01 +01:00
parent 128cf603e7
commit 6d839ebe9c

View File

@ -19,7 +19,7 @@ const NotificationContext = createContext()
const NotificationProvider = ({ children }) => {
const [api, contextHolder] = notification.useNotification()
const location = useLocation()
const { authenticated } = useContext(AuthContext)
const { authenticated, token } = useContext(AuthContext)
const {
showError,
fetchNotificationsApi,
@ -118,6 +118,12 @@ const NotificationProvider = ({ children }) => {
}
}, [authenticated, notificationCenterVisible, fetchNotifications])
useEffect(() => {
if (authenticated && token) {
fetchNotifications()
}
}, [authenticated, token, fetchNotifications])
useEffect(() => {
setNotificationCenterVisible(false)
}, [location.pathname])