From b7e757f3bae380b91ee162d09a9701cb1de09c19 Mon Sep 17 00:00:00 2001 From: diegosouzapw Date: Fri, 13 Feb 2026 17:29:51 -0300 Subject: [PATCH] fix(oauth): broaden upsert to match any existing connection Remove test_status restriction from the no-email upsert fallback. Now matches any existing OAuth connection for the same provider (not just failed ones), preventing duplicates regardless of status. --- src/lib/db/providers.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/db/providers.js b/src/lib/db/providers.js index 6586f476ac..202a510b5b 100644 --- a/src/lib/db/providers.js +++ b/src/lib/db/providers.js @@ -51,12 +51,11 @@ export async function createProviderConnection(data) { ) .get(data.provider, data.email); } else if (data.authType === "oauth" && !data.email) { - // Fallback for providers that don't return email (e.g. Codex): - // find the most recent failed connection for this provider to update instead of duplicating + // Fallback for providers that don't return email (e.g. Codex, Qwen): + // find the most recently updated connection for this provider to update instead of duplicating existing = db .prepare( `SELECT * FROM provider_connections WHERE provider = ? AND auth_type = 'oauth' - AND (test_status = 'auth_failed' OR test_status = 'refresh_failed' OR test_status = 'error') ORDER BY updated_at DESC LIMIT 1` ) .get(data.provider);