fix(codex): avoid bare-email OAuth dedup (#2477)

Only update an existing Codex OAuth row when both rows share the same
chatgptAccountId, so a second Codex login no longer overwrites the first
account's rotated token pair. Also fall back to
workspaceId || chatgptAccountId || accountId for the chatgpt-account-id header.
This commit is contained in:
Hermes Hunter authored and decolua committed 2026-07-10 11:41:43 +07:00
1 parent a3b267a5cb
commit c73c419d09
2 files changed
+23 -5

No files matched your search

+12 -1
View File
@@ -113,7 +113,18 @@ export async function createProviderConnection(data) {
const incomingWs = data.providerSpecificData?.chatgptAccountId;
existing = all.find(c => {
if (c.authType !== "oauth" || c.email !== data.email) return false;
// Workspace providers (Codex) use workspace ID when both sides have it
// Codex/OpenAI can issue multiple OAuth grants for the same email.
// Refresh tokens are rotated single-use; collapsing a new login onto an
// existing bare-email row overwrites the first account's token pair and
// makes it look "invalid" after adding a second account. Only update an
// existing Codex row when both rows expose the same ChatGPT account ID.
if (data.provider === "codex") {
const existingWs = c.providerSpecificData?.chatgptAccountId;
return !!incomingWs && !!existingWs && incomingWs === existingWs;
}
// Workspace providers use workspace ID when both sides have it
const existingWs = c.providerSpecificData?.chatgptAccountId;
if (incomingWs && existingWs) return incomingWs === existingWs;
if (incomingWs && !existingWs) return false;