fix: recover expired dashboard sessions (#309)
CI / lint (pull_request) Successful in 30s
CI / build-frontend (pull_request) Successful in 4s

This commit is contained in:
timmy committed 2026-08-08 14:32:37 +00:00
1 parent 6b99d4f171
commit 9786724678
8 files changed
+87 -10

No files matched your search

+7 -1
View File
@@ -11,6 +11,11 @@
const clearIntervalImpl = options.clearIntervalImpl || clearInterval;
let timer = null;
function showReason(reason) {
if (reason !== 'session-expired') return;
status.textContent = 'Your session expired. Private drafts remain on this device. Sign in to continue.';
}
function showRetryCountdown(seconds) {
let remaining = Math.max(1, Number.parseInt(seconds, 10) || 1);
button.disabled = true;
@@ -54,7 +59,7 @@
status.textContent = 'Sign-in failed. Check the token and try again.';
}
return { submit };
return { submit, showReason };
}));
if (typeof document !== 'undefined') {
@@ -68,6 +73,7 @@ if (typeof document !== 'undefined') {
fetchImpl: fetch.bind(window),
location: window.location,
});
controller.showReason(new URLSearchParams(window.location.search).get('reason'));
form.addEventListener('submit', event => {
event.preventDefault();
const accessToken = new FormData(form).get('access_token');
+1 -1
View File
@@ -1,6 +1,6 @@
const BASE = new URL('./', self.location.href).pathname;
importScripts(BASE + 'static/background-issue-sync.js');
const CACHE = 'stackchain-dashboard-shell-v30';
const CACHE = 'stackchain-dashboard-shell-v31';
const OUTAGE_STATUSES = new Set([500, 502, 503, 504]);
const SHELL = [
BASE,
+6 -1
View File
@@ -40,6 +40,7 @@
onClearError = () => {},
}) {
const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
let expirationStarted = false;
function csrfToken() {
const entry = String(cookie?.() || '').split(';')
@@ -63,7 +64,11 @@
requestOptions.headers = headers;
}
const response = await fetchImpl(input, requestOptions);
if (response.status === 401) onExpired();
if (response.status === 401 && isSameOrigin(input) && !expirationStarted) {
expirationStarted = true;
onExpired();
location.replace(base + 'login?reason=session-expired');
}
return response;
}