summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-12-04 22:57:39 -0500
committerDax Raad <[email protected]>2025-12-04 22:57:39 -0500
commit71e578eac9dd78324aa9d8e94c72afa767b86dc3 (patch)
tree636584cf2529e3a38abeef2d232d2b6e8d36a229
parent43807277272467fcc9a8af0618d88845c3edad96 (diff)
downloadopencode-71e578eac9dd78324aa9d8e94c72afa767b86dc3.tar.gz
opencode-71e578eac9dd78324aa9d8e94c72afa767b86dc3.zip
ignore: fix provider credentials query for BYOK
Provider credentials field was being selected from ProviderTable even when the table wasn't joined (when byokProvider was undefined). Now the join is conditional - when byokProvider exists, we join and get the credentials; when it doesn't, the join condition is always false so provider remains null.
-rw-r--r--packages/console/app/src/routes/zen/util/handler.ts21
1 files changed, 12 insertions, 9 deletions
diff --git a/packages/console/app/src/routes/zen/util/handler.ts b/packages/console/app/src/routes/zen/util/handler.ts
index a7f025bab..e34704f98 100644
--- a/packages/console/app/src/routes/zen/util/handler.ts
+++ b/packages/console/app/src/routes/zen/util/handler.ts
@@ -362,8 +362,8 @@ export async function handler(
throw new AuthError("Missing API key.")
}
- const data = await Database.use((tx) => {
- const query = tx
+ const data = await Database.use((tx) =>
+ tx
.select({
apiKey: KeyTable.id,
workspaceID: KeyTable.workspaceID,
@@ -391,15 +391,18 @@ export async function handler(
.innerJoin(BillingTable, eq(BillingTable.workspaceID, KeyTable.workspaceID))
.innerJoin(UserTable, and(eq(UserTable.workspaceID, KeyTable.workspaceID), eq(UserTable.id, KeyTable.userID)))
.leftJoin(ModelTable, and(eq(ModelTable.workspaceID, KeyTable.workspaceID), eq(ModelTable.model, modelInfo.id)))
-
- if (modelInfo.byokProvider) {
- query.leftJoin(
+ .leftJoin(
ProviderTable,
- and(eq(ProviderTable.workspaceID, KeyTable.workspaceID), eq(ProviderTable.provider, modelInfo.byokProvider)),
+ modelInfo.byokProvider
+ ? and(
+ eq(ProviderTable.workspaceID, KeyTable.workspaceID),
+ eq(ProviderTable.provider, modelInfo.byokProvider),
+ )
+ : sql`false`,
)
- }
- return query.where(and(eq(KeyTable.key, apiKey), isNull(KeyTable.timeDeleted))).then((rows) => rows[0])
- })
+ .where(and(eq(KeyTable.key, apiKey), isNull(KeyTable.timeDeleted)))
+ .then((rows) => rows[0]),
+ )
if (!data) throw new AuthError("Invalid API key.")
logger.metric({