From 54d5b18b1e0dc70e057eff7f7fbf1e0c9436b3ad Mon Sep 17 00:00:00 2001 From: cliffhall Date: Wed, 8 Jul 2026 13:54:14 -0400 Subject: [PATCH] fix(auth): drop redundant empty-object guard in remote OAuth read() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parseOAuthPersistBlob already returns null for {} (the server's missing-file response) and for a literal null body, so the Object.keys(store).length === 0 guard was redundant — and would throw a TypeError on a null body before parseOAuthPersistBlob could handle it. Pass the parsed res.json() straight through. Addresses Claude review item #1 on #1612. Co-Authored-By: Claude Opus 4.8 (1M context) --- core/auth/oauth-persist.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/core/auth/oauth-persist.ts b/core/auth/oauth-persist.ts index ed635ba2..66d36c7d 100644 --- a/core/auth/oauth-persist.ts +++ b/core/auth/oauth-persist.ts @@ -26,7 +26,9 @@ function isRecord(value: unknown): value is Record { return typeof value === "object" && value !== null && !Array.isArray(value); } -function snapshotFromPayload(payload: Partial): OAuthPersistSnapshot { +function snapshotFromPayload( + payload: Partial, +): OAuthPersistSnapshot { return { servers: payload.servers ?? {}, idpSessions: payload.idpSessions ?? {}, @@ -45,12 +47,7 @@ export function parseOAuthPersistBlob( return null; } - const parsed = - typeof raw === "string" - ? raw - ? parseStore(raw) - : null - : raw; + const parsed = typeof raw === "string" ? (raw ? parseStore(raw) : null) : raw; if (!isRecord(parsed)) { return null; @@ -135,10 +132,10 @@ export function createRemoteOAuthPersistBackend( throw new Error(`Failed to read store: ${res.status}`); } + // parseOAuthPersistBlob already returns null for {} (the server's + // missing-file response, server.ts) and for a literal null body, so no + // empty-object guard is needed — and Object.keys(null) would throw. const store = await res.json(); - if (Object.keys(store as object).length === 0) { - return null; - } return parseOAuthPersistBlob(store); }, async write(snapshot) {