fix: remove stale encrypted OpenRouter key when cleared

When the user clears their OpenRouter key (switching to Venice-only),
_flushSaveState now removes the g0dm0d3-apikey localStorage entry.
Previously the encrypted key survived and was restored on reload,
silently resuming OpenRouter requests.

Also guards against a race where an older async encryptApiKey resolves
after the key was already changed — only writes if state.apiKey still
matches the value that was encrypted.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
faber
2026-07-11 14:10:13 -04:00
parent 40c310f566
commit eeff0ce2db

View File

@@ -12423,9 +12423,14 @@ Ignoring conversation history will cause you to LOSE the evaluation.`;
// Persist encrypted key separately (async, best-effort)
if (apiKey) {
encryptApiKey(apiKey).then(enc => {
try { localStorage.setItem('g0dm0d3-apikey', enc); } catch (_) {}
const keyAtFlush = apiKey;
encryptApiKey(keyAtFlush).then(enc => {
if (state.apiKey === keyAtFlush) {
try { localStorage.setItem('g0dm0d3-apikey', enc); } catch (_) {}
}
});
} else {
localStorage.removeItem('g0dm0d3-apikey');
}
try {