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
+24
-2
@@ -1,18 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from "pinia";
|
||||
import { onMounted } from "vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
import ChatLauncher from "@/chat/ChatLauncher.vue";
|
||||
import CommandPalette from "@/components/command-palette/CommandPalette.vue";
|
||||
import Topbar from "@/components/topbar/Topbar.vue";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { hidden, loadCapabilities } from "@/lib/capabilities";
|
||||
import { createSessionRetry } from "@/lib/session-retry";
|
||||
import { loadTaskMeta } from "@/lib/task-meta";
|
||||
import { useLiveUpdatesStore } from "@/stores/live-updates";
|
||||
|
||||
const { authenticationRequired } = storeToRefs(useLiveUpdatesStore());
|
||||
|
||||
// Re-runs the reads that report their own 401s to the live-updates store. A
|
||||
// session that came back clears the banner without a document reload; one that
|
||||
// did not leaves it up.
|
||||
const retrying = ref(false);
|
||||
const retrySession = createSessionRetry([loadCapabilities, loadTaskMeta]);
|
||||
|
||||
async function retryAuthentication(): Promise<void> {
|
||||
retrying.value = true;
|
||||
try {
|
||||
await retrySession();
|
||||
} finally {
|
||||
retrying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// Asked for once, after the shell is up: the nav paints immediately and
|
||||
// loses the entries this process cannot back a moment later, rather than
|
||||
@@ -51,6 +68,11 @@ onMounted(() => {
|
||||
<AlertDescription>
|
||||
Open the dashboard URL Archie logged at startup to establish a new authenticated session.
|
||||
</AlertDescription>
|
||||
<AlertAction>
|
||||
<Button variant="outline" size="sm" :disabled="retrying" @click="retryAuthentication">
|
||||
{{ retrying ? "Retrying…" : "Retry" }}
|
||||
</Button>
|
||||
</AlertAction>
|
||||
</Alert>
|
||||
<!--
|
||||
Keyed on the path and its parameters but not the query: a query-only
|
||||
|
||||
@@ -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