MCPcopy Index your code
hub / github.com/21st-dev/1code / save

Method save

src/main/auth-store.ts:42–64  ·  view source on GitHub ↗

* Save authentication data (encrypted if possible)

(data: AuthData)

Source from the content-addressed store, hash-verified

40 * Save authentication data (encrypted if possible)
41 */
42 save(data: AuthData): void {
43 try {
44 const dir = dirname(this.filePath)
45 if (!existsSync(dir)) {
46 mkdirSync(dir, { recursive: true })
47 }
48
49 const jsonData = JSON.stringify(data)
50
51 if (this.isEncryptionAvailable()) {
52 // Encrypt using OS keychain (macOS Keychain, Windows DPAPI, Linux Secret Service)
53 const encrypted = safeStorage.encryptString(jsonData)
54 writeFileSync(this.filePath, encrypted)
55 } else {
56 // Fallback: store with warning (should rarely happen)
57 console.warn("safeStorage not available - storing auth data without encryption")
58 writeFileSync(this.filePath + ".json", jsonData, "utf-8")
59 }
60 } catch (error) {
61 console.error("Failed to save auth data:", error)
62 throw error
63 }
64 }
65
66 /**
67 * Load authentication data (decrypts if encrypted)

Callers 4

loadMethod · 0.95
updateUserMethod · 0.95
exchangeCodeMethod · 0.45
refreshMethod · 0.45

Calls 1

isEncryptionAvailableMethod · 0.95

Tested by

no test coverage detected