fix(auth): skip auth:expired dispatch for 401 on /auth/login (#69)

On Safari/iOS PWA cold start or after cookie clear, logging in with wrong
credentials triggered auth:expired, re-rendering the login page and losing
the error message. The login endpoint returns 401 for invalid credentials,
not for session expiry, so apiFetch must not fire auth:expired in that path.

Resolves #68

Co-authored-by: Ulas Kalayci <ulas.kalayci@googlemail.com>
This commit is contained in:
ulsklyc
2026-04-20 21:37:29 +02:00
committed by GitHub
parent 554024b67c
commit 9ad1165d48
4 changed files with 127 additions and 5 deletions
+7 -3
View File
@@ -44,9 +44,13 @@ async function apiFetch(path, options = {}, _retried = false) {
});
if (response.status === 401) {
// Session abgelaufen → zur Login-Seite
window.dispatchEvent(new CustomEvent('auth:expired'));
throw new Error('Sitzung abgelaufen.');
// Beim Login-Endpunkt bedeutet 401 "falsche Zugangsdaten", nicht "Session abgelaufen".
// auth:expired würde die Login-Seite neu rendern und die Fehlermeldung verwerfen.
if (path !== '/auth/login') {
window.dispatchEvent(new CustomEvent('auth:expired'));
throw new Error('Sitzung abgelaufen.');
}
// Für /auth/login: fall-through zum generischen !response.ok-Handler unten.
}
// CSRF-Token-Desync (haeufig nach iOS-PWA-Resume): einmal GET /auth/me