From 1d2a57352fdc8022c4fc2a7d820c6c87f98441f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=B6rdle=20Bot?= Date: Fri, 21 Nov 2025 20:52:08 +0100 Subject: [PATCH] feat(admin): add persistent login and improve audio playback error handling --- app/admin/page.tsx | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/app/admin/page.tsx b/app/admin/page.tsx index fb6a854..c5c2157 100644 --- a/app/admin/page.tsx +++ b/app/admin/page.tsx @@ -39,12 +39,22 @@ export default function AdminPage() { const [playingSongId, setPlayingSongId] = useState(null); const [audioElement, setAudioElement] = useState(null); + // Check for existing auth on mount + useEffect(() => { + const authToken = localStorage.getItem('hoerdle_admin_auth'); + if (authToken === 'authenticated') { + setIsAuthenticated(true); + fetchSongs(); + } + }, []); + const handleLogin = async () => { const res = await fetch('/api/admin/login', { method: 'POST', body: JSON.stringify({ password }), }); if (res.ok) { + localStorage.setItem('hoerdle_admin_auth', 'authenticated'); setIsAuthenticated(true); fetchSongs(); } else { @@ -147,9 +157,25 @@ export default function AdminPage() { // Play new song const audio = new Audio(`/uploads/${song.filename}`); - audio.play(); - setAudioElement(audio); - setPlayingSongId(song.id); + + // Handle playback errors + audio.onerror = () => { + alert(`Failed to load audio file: ${song.filename}\nThe file may be corrupted or missing.`); + setPlayingSongId(null); + setAudioElement(null); + }; + + audio.play() + .then(() => { + setAudioElement(audio); + setPlayingSongId(song.id); + }) + .catch((error) => { + console.error('Playback error:', error); + alert(`Failed to play audio: ${error.message}`); + setPlayingSongId(null); + setAudioElement(null); + }); // Reset when song ends audio.onended = () => {