From a0a972b53a8ef9e8dd03dd715c5d4b46226bb89a Mon Sep 17 00:00:00 2001 From: Michelle Date: Fri, 13 Mar 2026 13:00:54 +0100 Subject: [PATCH] fix(NotificationContext): ensure audio playback is unlocked only for authenticated users --- src/contexts/NotificationContext.jsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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();