MCPcopy Create free account
hub / github.com/Noumena-Network/code / update

Function update

src/utils/secureStorage/fallbackStorage.ts:27–62  ·  view source on GitHub ↗
(data: SecureStorageData)

Source from the content-addressed store, hash-verified

25 return (await secondary.readAsync()) || {}
26 },
27 update(data: SecureStorageData): { success: boolean; warning?: string } {
28 // Capture state before update
29 const primaryDataBefore = primary.read()
30
31 const result = primary.update(data)
32
33 if (result.success) {
34 // Delete secondary when migrating to primary for the first time
35 // This preserves credentials when sharing .claude between host and containers
36 // See: upstream issue context in source history
37 if (primaryDataBefore === null) {
38 secondary.delete()
39 }
40 return result
41 }
42
43 const fallbackResult = secondary.update(data)
44
45 if (fallbackResult.success) {
46 // Primary write failed but primary may still hold an *older* valid
47 // entry. read() prefers primary whenever it returns non-null, so that
48 // stale entry would shadow the fresh data we just wrote to secondary —
49 // e.g. a refresh token the server has already rotated away, causing a
50 // /login loop (#30337). Best-effort delete; if this also fails the
51 // user's keychain is in a bad state we can't fix from here.
52 if (primaryDataBefore !== null) {
53 primary.delete()
54 }
55 return {
56 success: true,
57 warning: fallbackResult.warning,
58 }
59 }
60
61 return { success: false }
62 },
63 delete(): boolean {
64 const primarySuccess = primary.delete()
65 const secondarySuccess = secondary.delete()

Callers 1

onStreamingThinkingFunction · 0.50

Calls 2

deleteMethod · 0.80
readMethod · 0.45

Tested by 1

onStreamingThinkingFunction · 0.40