MCPcopy Create free account
hub / github.com/OpenAnonymity/oa-chat / setApiKey

Method setApiKey

chat/services/apiKeyStore.js:89–123  ·  view source on GitHub ↗
(apiKeyData)

Source from the content-addressed store, hash-verified

87 }
88
89 async setApiKey(apiKeyData) {
90 try {
91 this.state = {
92 apiKey: apiKeyData.key,
93 apiKeyInfo: apiKeyData,
94 expiresAt: apiKeyData.expiresAt || apiKeyData.expires_at,
95 ticketUsed: apiKeyData.ticketUsed || apiKeyData.ticket_used
96 };
97
98 let persisted = false;
99 if (typeof chatDB !== 'undefined') {
100 if (!chatDB.db && typeof chatDB.init === 'function') {
101 await chatDB.init();
102 }
103 if (chatDB.db) {
104 await chatDB.saveSetting(ACCESS_DB_KEY, apiKeyData);
105 persisted = true;
106 }
107 }
108
109 if (persisted) {
110 localStorage.removeItem(ACCESS_STORAGE_KEY);
111 console.log('💾 Saved API key to IndexedDB');
112 } else {
113 localStorage.setItem(ACCESS_STORAGE_KEY, JSON.stringify(apiKeyData));
114 console.warn('💾 Saved API key to localStorage (IndexedDB unavailable)');
115 }
116
117 window.dispatchEvent(new CustomEvent('apikey-changed'));
118 this.notify();
119 } catch (error) {
120 console.error('❌ Error saving API key:', error);
121 throw error;
122 }
123 }
124
125 clearApiKey() {
126 this.state = {

Callers

nothing calls this directly

Calls 3

notifyMethod · 0.95
saveSettingMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected