feat(webui): give the dashboard an actionable auth failure state
An unauthenticated document request answered with a plain-text 401 -- and index.html, the bundle and every asset sit behind requireToken -- so a bookmarked or bare URL was a dead end: the dashboard's own authentication banner could never load to explain it. Document requests now get a self-contained 401 page whose one-field form reuses the ?t= exchange, so a pasted token sets the cookie and the redirect lands on the dashboard. A rejected token re-renders the page with the reason instead of answering a document with text. API and event-stream callers keep the plain-text 401: classifyActionError maps it to "session-expired", and an EventSource error body is never seen. The auth banner gains a Retry that re-runs the reads which report their own 401s, so a recovered session clears it without a document reload. The retry is extracted to lib/session-retry.ts with an in-flight guard and unit tests.
This commit is contained in:
6 files changed
+300
-11
No files matched your search
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* A retry that re-runs the reads which establish whether the dashboard's
|
||||
* session is valid, without reloading the document.
|
||||
*
|
||||
* It knows nothing about authentication: the reads report their own 401s to
|
||||
* `setAuthenticationStateHandler`, so a successful retry clears the banner and
|
||||
* a still-expired session leaves it up. The in-flight guard means a double
|
||||
* click runs the reads once.
|
||||
*/
|
||||
export function createSessionRetry(
|
||||
loads: Array<() => Promise<unknown> | void>,
|
||||
): () => Promise<void> {
|
||||
let running = false;
|
||||
return async () => {
|
||||
if (running) return;
|
||||
running = true;
|
||||
try {
|
||||
await Promise.all(loads.map((load) => load()));
|
||||
} finally {
|
||||
running = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user