Преглед изворни кода

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.
Dax Raad пре 2 месеци
родитељ
комит
71e578eac9
1 измењених фајлова са 12 додато и 9 уклоњено
  1. 12 9
      packages/console/app/src/routes/zen/util/handler.ts

+ 12 - 9
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({