fix: keep session when refresh fails on network error or 5xx (WealthLedger/frontend#97)
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 1m3s
Frontend verify / verify (push) Failing after 7m11s

This commit was merged in pull request #100.
This commit is contained in:
2026-10-23 15:06:20 +03:00
parent 7b6f34c776
commit 3af9df0ae2
9 changed files with 154 additions and 15 deletions
+6 -1
View File
@@ -32,6 +32,10 @@ type AuthHandlers = {
clear: () => void;
generation?: () => number;
refresh: () => Promise<boolean>;
/**
True after a refresh failed transiently (network/5xx): the session is not proven gone.
*/
unavailable?: () => boolean;
};
type ReadAttempt = {
@@ -100,7 +104,8 @@ async function authenticatedFetch(request: Request): Promise<Response> {
if (!isCurrent()) throw new DOMException("Session changed", "AbortError");
if (!(await sessionState.handlers.refresh())) {
if (isCurrent()) sessionState.handlers.clear();
if (isCurrent() && !sessionState.handlers.unavailable?.())
sessionState.handlers.clear();
return response;
}