mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-19 06:45:50 +00:00
fix: 登录后清理 OpenAI 客户端缓存和 ChatGPT auth 防止凭证泄漏
OpenAI Compatible / ChatGPT Subscription / 中国区登录成功后,清除 缓存的 OpenAI 客户端实例和 ChatGPT auth 文件,确保下次请求使用新凭证。 Co-Authored-By: deepseek-v4-pro <deepseek-ai@claude-code-best.win>
This commit is contained in:
@@ -11,9 +11,11 @@ import { getSSLErrorHint } from '@ant/model-provider';
|
|||||||
import { sendNotification } from '../services/notifier.js';
|
import { sendNotification } from '../services/notifier.js';
|
||||||
import {
|
import {
|
||||||
completeChatGPTDeviceLogin,
|
completeChatGPTDeviceLogin,
|
||||||
|
removeChatGPTAuth,
|
||||||
requestChatGPTDeviceCode,
|
requestChatGPTDeviceCode,
|
||||||
type ChatGPTDeviceCode,
|
type ChatGPTDeviceCode,
|
||||||
} from '../services/api/openai/chatgptAuth.js';
|
} from '../services/api/openai/chatgptAuth.js';
|
||||||
|
import { clearOpenAIClientCache } from '../services/api/openai/client.js';
|
||||||
import { OAuthService } from '../services/oauth/index.js';
|
import { OAuthService } from '../services/oauth/index.js';
|
||||||
import { getOauthAccountInfo, validateForceLoginOrg } from '../utils/auth.js';
|
import { getOauthAccountInfo, validateForceLoginOrg } from '../utils/auth.js';
|
||||||
import { openBrowser } from '../utils/browser.js';
|
import { openBrowser } from '../utils/browser.js';
|
||||||
@@ -909,6 +911,11 @@ function OAuthStatusMessage({
|
|||||||
process.env[k] = v;
|
process.env[k] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Drop any cached OpenAI client so the next request rebuilds it
|
||||||
|
// with the new env vars. Also clear ChatGPT auth file so a prior
|
||||||
|
// ChatGPT Subscription login can't leak into the OpenAI Compatible path.
|
||||||
|
clearOpenAIClientCache();
|
||||||
|
void removeChatGPTAuth().catch(() => {});
|
||||||
setOAuthStatus({ state: 'success' });
|
setOAuthStatus({ state: 'success' });
|
||||||
void onDone();
|
void onDone();
|
||||||
}
|
}
|
||||||
@@ -1043,6 +1050,11 @@ function OAuthStatusMessage({
|
|||||||
throw new Error('Failed to save settings. Please try again.');
|
throw new Error('Failed to save settings. Please try again.');
|
||||||
}
|
}
|
||||||
for (const [k, v] of Object.entries(env)) process.env[k] = v;
|
for (const [k, v] of Object.entries(env)) process.env[k] = v;
|
||||||
|
// Drop any cached OpenAI client built from prior OpenAI Compatible
|
||||||
|
// env vars; the ChatGPT Subscription path bypasses the SDK client
|
||||||
|
// entirely (uses createChatGPTResponsesStream) but a stale cached
|
||||||
|
// client would still be picked up by sideQuery.
|
||||||
|
clearOpenAIClientCache();
|
||||||
setOAuthStatus({ state: 'success' });
|
setOAuthStatus({ state: 'success' });
|
||||||
void onDone();
|
void onDone();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -1468,6 +1480,10 @@ function OAuthStatusMessage({
|
|||||||
process.env[k] = v;
|
process.env[k] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Drop any cached OpenAI client and ChatGPT auth so the new
|
||||||
|
// provider/credentials take effect on the next request.
|
||||||
|
clearOpenAIClientCache();
|
||||||
|
void removeChatGPTAuth().catch(() => {});
|
||||||
logEvent('tengu_china_login_success', {});
|
logEvent('tengu_china_login_success', {});
|
||||||
setOAuthStatus({ state: 'success' });
|
setOAuthStatus({ state: 'success' });
|
||||||
void onDone();
|
void onDone();
|
||||||
|
|||||||
Reference in New Issue
Block a user