diff --git a/src/lib/db/providers.ts b/src/lib/db/providers.ts index d22842b2ed..47a18fee9f 100644 --- a/src/lib/db/providers.ts +++ b/src/lib/db/providers.ts @@ -55,6 +55,10 @@ export async function getProviderConnections(filter: JsonRecord = {}) { conditions.push("is_active = @isActive"); params.isActive = filter.isActive ? 1 : 0; } + if (filter.authType) { + conditions.push("auth_type = @authType"); + params.authType = filter.authType; + } if (conditions.length > 0) { sql += " WHERE " + conditions.join(" AND "); diff --git a/tests/unit/db-providers-crud.test.ts b/tests/unit/db-providers-crud.test.ts index 38babb66b1..9c005fc179 100644 --- a/tests/unit/db-providers-crud.test.ts +++ b/tests/unit/db-providers-crud.test.ts @@ -81,6 +81,34 @@ test("createProviderConnection assigns provider-scoped priorities and supports f assert.equal(second.isActive, false); }); +test("getProviderConnections filters by authType", async () => { + const apiKeyConnection = await providersDb.createProviderConnection({ + provider: "openai", + authType: "apikey", + name: "API Key Connection", + apiKey: "sk-apikey", + }); + const oauthConnection = await providersDb.createProviderConnection({ + provider: "claude", + authType: "oauth", + email: "oauth@example.com", + accessToken: "token-a", + refreshToken: "refresh-a", + }); + + const oauthOnly = await providersDb.getProviderConnections({ authType: "oauth" }); + const apiKeyOnly = await providersDb.getProviderConnections({ authType: "apikey" }); + + assert.deepEqual( + oauthOnly.map((connection) => connection.id), + [oauthConnection.id] + ); + assert.deepEqual( + apiKeyOnly.map((connection) => connection.id), + [apiKeyConnection.id] + ); +}); + test("oauth connections upsert by provider and email instead of duplicating rows", async () => { const original = await providersDb.createProviderConnection({ provider: "claude",