MCPcopy
hub / github.com/21st-dev/1code / load

Method load

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

* Load authentication data (decrypts if encrypted)

()

Source from the content-addressed store, hash-verified

67 * Load authentication data (decrypts if encrypted)
68 */
69 load(): AuthData | null {
70 try {
71 // Try encrypted file first
72 if (existsSync(this.filePath) && this.isEncryptionAvailable()) {
73 const encrypted = readFileSync(this.filePath)
74 const decrypted = safeStorage.decryptString(encrypted)
75 return JSON.parse(decrypted)
76 }
77
78 // Fallback: try unencrypted file (for migration or when encryption unavailable)
79 const fallbackPath = this.filePath + ".json"
80 if (existsSync(fallbackPath)) {
81 const content = readFileSync(fallbackPath, "utf-8")
82 const data = JSON.parse(content)
83
84 // Migrate to encrypted storage if now available
85 if (this.isEncryptionAvailable()) {
86 this.save(data)
87 unlinkSync(fallbackPath) // Remove unencrypted file after migration
88 }
89
90 return data
91 }
92
93 // Legacy: check for old auth.json file and migrate
94 const legacyPath = join(dirname(this.filePath), "auth.json")
95 if (existsSync(legacyPath)) {
96 const content = readFileSync(legacyPath, "utf-8")
97 const data = JSON.parse(content)
98
99 // Migrate to encrypted storage
100 this.save(data)
101 unlinkSync(legacyPath) // Remove legacy unencrypted file
102 console.log("Migrated auth data from plaintext to encrypted storage")
103
104 return data
105 }
106
107 return null
108 } catch {
109 console.error("Failed to load auth data")
110 return null
111 }
112 }
113
114 /**
115 * Clear all stored authentication data (both encrypted and fallback files)

Callers 8

isAuthenticatedMethod · 0.95
getUserMethod · 0.95
getTokenMethod · 0.95
getRefreshTokenMethod · 0.95
needsRefreshMethod · 0.95
updateUserMethod · 0.95
scheduleRefreshMethod · 0.45
getAuthMethod · 0.45

Calls 2

isEncryptionAvailableMethod · 0.95
saveMethod · 0.95

Tested by

no test coverage detected