diff --git a/src/contexts/NotificationContext.jsx b/src/contexts/NotificationContext.jsx index e4d1fda..5a6638a 100644 --- a/src/contexts/NotificationContext.jsx +++ b/src/contexts/NotificationContext.jsx @@ -98,10 +98,10 @@ export function NotificationProvider({ children }) { } }, [user]); - // Unlock audio playback on the first real user interaction. - // Browsers block audio from timer callbacks unless the element was previously - // "touched" inside a gesture handler — this one-time listener does exactly that. + // Unlock audio playback only for authenticated sessions. + // This avoids any audio interaction while logged out (e.g. anonymous/incognito tabs). useEffect(() => { + if (!user?.id) return; const events = ['click', 'keydown', 'pointerdown']; const handler = () => { unlockAudio(); @@ -109,11 +109,12 @@ export function NotificationProvider({ children }) { }; events.forEach(e => window.addEventListener(e, handler, { once: true })); return () => events.forEach(e => window.removeEventListener(e, handler)); - }, []); + }, [user?.id]); useEffect(() => { activeUserId.current = user?.id ?? null; if (!user) { + _audioUnlocked = false; setNotifications([]); setUnreadCount(0); seenIds.current = new Set();