v2.0.4 — re-auth on 401, robust bucket-switch test
- auth: when a background poll or save returns 401 (session expired while the UI is still open), the api() helpers now prompt for the password instead of letting the save fail silently. Concurrent 401s collapse onto a single dialog via a shared reauthPromise, and each caller retries its original request once after login. /api/auth/* is excluded from the retry path. Extracts promptLogin() in app.js and exposes it as window._reauth so both the core util.js api() and the plugin-SDK hyprcrd.js api() can share the flow. - tests: the "open-switches-bucket" detail test assumed buckets[0] was a plain top-level bucket, but the bar renders super-bucket parents with data-bucket-super and hides child buckets entirely, so the .bucket-tab.active[data-bucket] selector found nothing on setups with nested layouts. Test now picks two plain top-level buckets or skips. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
48b5907f4c
commit
f986a41ccc
6 files changed
+76
-28
No files matched your search
+19
-8
@@ -127,15 +127,26 @@
|
||||
csrf() { return csrfToken; },
|
||||
};
|
||||
|
||||
/** Generic JSON API call with automatic CSRF header. */
|
||||
/** Generic JSON API call with automatic CSRF header.
|
||||
* On 401 (session expired while the UI is open) we call the app's
|
||||
* re-auth prompt once, pick up the refreshed CSRF token, and retry
|
||||
* the original request so the caller's save / poll succeeds instead
|
||||
* of silently returning an unauthorized error payload. */
|
||||
async function api(path, opts = {}) {
|
||||
const headers = { 'Content-Type': 'application/json' };
|
||||
if (csrfToken) headers['X-CSRF-Token'] = csrfToken;
|
||||
const res = await fetch(path, {
|
||||
method: opts.method || 'GET',
|
||||
headers,
|
||||
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
||||
});
|
||||
const doFetch = () => {
|
||||
const headers = { 'Content-Type': 'application/json' };
|
||||
if (csrfToken) headers['X-CSRF-Token'] = csrfToken;
|
||||
return fetch(path, {
|
||||
method: opts.method || 'GET',
|
||||
headers,
|
||||
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
||||
});
|
||||
};
|
||||
let res = await doFetch();
|
||||
if (res.status === 401 && !path.startsWith('api/auth/') && typeof window._reauth === 'function') {
|
||||
await window._reauth();
|
||||
res = await doFetch();
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user