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:
+7
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user