fix: integrate final user-provided notification sound and clean up unused assets
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m4s
All checks were successful
Build and Deploy / build-and-push (push) Successful in 2m4s
- Replaced placeholder audio with the requested high-quality sound file. - Removed deprecated audio files from the public directory.
This commit is contained in:
35
debug.txt
35
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.
|
||||
|
||||
Reference in New Issue
Block a user