* Save authentication data (encrypted if possible)
(data: AuthData)
| 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) |
no test coverage detected