Skip to content

Commit b83395c

Browse files
claude-code-bestdeepseek-v4-pro
andcommitted
fix: 登录后清理 OpenAI 客户端缓存和 ChatGPT auth 防止凭证泄漏
OpenAI Compatible / ChatGPT Subscription / 中国区登录成功后,清除 缓存的 OpenAI 客户端实例和 ChatGPT auth 文件,确保下次请求使用新凭证。 Co-Authored-By: deepseek-v4-pro <deepseek-ai@claude-code-best.win>
1 parent ddf1acd commit b83395c

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/components/ConsoleOAuthFlow.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import { getSSLErrorHint } from '@ant/model-provider';
1111
import { sendNotification } from '../services/notifier.js';
1212
import {
1313
completeChatGPTDeviceLogin,
14+
removeChatGPTAuth,
1415
requestChatGPTDeviceCode,
1516
type ChatGPTDeviceCode,
1617
} from '../services/api/openai/chatgptAuth.js';
18+
import { clearOpenAIClientCache } from '../services/api/openai/client.js';
1719
import { OAuthService } from '../services/oauth/index.js';
1820
import { getOauthAccountInfo, validateForceLoginOrg } from '../utils/auth.js';
1921
import { openBrowser } from '../utils/browser.js';
@@ -909,6 +911,11 @@ function OAuthStatusMessage({
909911
process.env[k] = v;
910912
}
911913
}
914+
// Drop any cached OpenAI client so the next request rebuilds it
915+
// with the new env vars. Also clear ChatGPT auth file so a prior
916+
// ChatGPT Subscription login can't leak into the OpenAI Compatible path.
917+
clearOpenAIClientCache();
918+
void removeChatGPTAuth().catch(() => {});
912919
setOAuthStatus({ state: 'success' });
913920
void onDone();
914921
}
@@ -1043,6 +1050,11 @@ function OAuthStatusMessage({
10431050
throw new Error('Failed to save settings. Please try again.');
10441051
}
10451052
for (const [k, v] of Object.entries(env)) process.env[k] = v;
1053+
// Drop any cached OpenAI client built from prior OpenAI Compatible
1054+
// env vars; the ChatGPT Subscription path bypasses the SDK client
1055+
// entirely (uses createChatGPTResponsesStream) but a stale cached
1056+
// client would still be picked up by sideQuery.
1057+
clearOpenAIClientCache();
10461058
setOAuthStatus({ state: 'success' });
10471059
void onDone();
10481060
} catch (err) {
@@ -1468,6 +1480,10 @@ function OAuthStatusMessage({
14681480
process.env[k] = v;
14691481
}
14701482
}
1483+
// Drop any cached OpenAI client and ChatGPT auth so the new
1484+
// provider/credentials take effect on the next request.
1485+
clearOpenAIClientCache();
1486+
void removeChatGPTAuth().catch(() => {});
14711487
logEvent('tengu_china_login_success', {});
14721488
setOAuthStatus({ state: 'success' });
14731489
void onDone();

0 commit comments

Comments
 (0)