fix(auth): reject load() when persist read fails

This commit is contained in:
Bob Dickinson 2026-07-03 14:50:04 -07:00
commit 512f45d357
2 changed files with 91 additions and 10 deletions

View file

@ -2191,7 +2191,15 @@ function App() {
}
void (async () => {
await webOAuthStorage.load();
try {
await webOAuthStorage.load();
} catch (err) {
connectStartRef.current = undefined;
queueMicrotask(() => {
showReAuthBanner(server.id, err instanceof Error ? err : String(err));
});
return;
}
const client = setupClientForServer(server, sessionId);
setActiveServerId(server.id);
try {

View file

@ -1,5 +1,9 @@
import { describe, it, expect, beforeEach, vi } from "vitest";
import { RemoteOAuthStorage } from "@inspector/core/auth/remote/storage-remote.js";
import {
type OAuthStore,
waitForOAuthStorePersistLoad,
} from "@inspector/core/auth/store.js";
const NOOP_FETCH = vi.fn(
async () =>
@ -121,6 +125,12 @@ describe("RemoteOAuthStorage (unit, mocked fetch)", () => {
expect(s).toBeInstanceOf(RemoteOAuthStorage);
});
it("waitForOAuthStorePersistLoad resolves for an unregistered store handle", async () => {
await expect(
waitForOAuthStorePersistLoad({} as OAuthStore),
).resolves.toBeUndefined();
});
it("load() waits for remote GET before sync reads see persisted state", async () => {
const persisted = {
state: {
@ -155,4 +165,20 @@ describe("RemoteOAuthStorage (unit, mocked fetch)", () => {
"persisted-verifier",
);
});
it("load() rejects when remote GET fails instead of hanging", async () => {
const failingFetch = vi.fn(
async () => new Response("server error", { status: 500 }),
) as unknown as typeof fetch;
const failingStorage = new RemoteOAuthStorage({
baseUrl: "http://remote.example",
storeId: `fail-${Math.random().toString(36).slice(2)}`,
fetchFn: failingFetch,
});
await expect(failingStorage.load()).rejects.toThrow(
"Failed to read store: 500",
);
});
});