diff --git a/debug.txt b/debug.txt index e700b38..8cf10a2 100644 --- a/debug.txt +++ b/debug.txt @@ -1,12 +1,27 @@ -Look at line 354: `if (req.user.role !== 'super_admin' && rows[0].tenant_id !== req.user.tenant_id) {` -What if `req.user.tenant_id` is null (which it is for some system admins)? -But `rows[0].tenant_id` could be something else. That just returns 403. -What if `rows` is empty? -Line 353: `if (rows.length === 0) return res.status(404).json({ error: 'Not found' });` -What if `req.user` is undefined? (Should be caught by middleware). +Look at `playNotificationSound`: +```javascript + const playNotificationSound = () => { + if (currentUser?.sound_enabled !== false && audioRef.current) { + // Reset time to 0 to allow rapid replays + audioRef.current.currentTime = 0; + const playPromise = audioRef.current.play(); +``` +Is `currentUser` loaded when `loadNotifications` fires for the first time after `isInitialLoadRef` is false? +Yes, `useEffect` calls `fetchCurrentUser()`, which sets `currentUser`. -Wait, the user says the error is: -`https://fasto.blyzer.com.br/api/users/u_71657ec7` -And it returns `500`. +Wait. `setInterval` uses a closure over the state! +```javascript + useEffect(() => { + fetchCurrentUser(); + loadNotifications(); + const interval = setInterval(loadNotifications, 10000); + return () => clearInterval(interval); + }, [navigate]); +``` +Oh my god. The `setInterval` callback `loadNotifications` captures the *initial* state variables, including `currentUser`, which is `null` on the first render! +If `currentUser` is `null` inside the closure, `currentUser?.sound_enabled !== false` evaluates to `true !== false` which is `true`. So that's not blocking it. +BUT `audioRef.current` might not have been rendered yet? No, `audioRef` is a ref, so it mutates in place. The closure always sees the latest `audioRef.current`. -Let's log the exact error inside the catch block in the backend. +So why does it fail or not play? +Is the browser policy blocking it silently without logging? +Let's add a robust, standalone Audio approach that doesn't rely on the DOM tag if it fails, or maybe just force a click handler to "unlock" the audio context. diff --git a/public/audio/notification.mp3 b/public/audio/notification.mp3 deleted file mode 100644 index 321a551..0000000 --- a/public/audio/notification.mp3 +++ /dev/null @@ -1,9 +0,0 @@ - -
-The requested URL was not found on this server.
-Additionally, a 404 Not Found -error was encountered while trying to use an ErrorDocument to handle the request.
- diff --git a/src/assets/audio/notification.mp3 b/src/assets/audio/notification.mp3 index de51d68..e6e2336 100644 Binary files a/src/assets/audio/notification.mp3 and b/src/assets/audio/notification.mp3 differ