From 005f18262bfbc37e8fd03d601c363c027956df92 Mon Sep 17 00:00:00 2001 From: Fred Liang Date: Mon, 25 Dec 2023 10:17:10 +0800 Subject: [PATCH] chore: update auth value logic --- app/api/common.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index a6f4c5721a1..2d89ea1e518 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -9,17 +9,21 @@ const serverConfig = getServerSideConfig(); export async function requestOpenai(req: NextRequest) { const controller = new AbortController(); + var authValue, + authHeaderName = ""; if (serverConfig.isAzure) { - const authValue = + authValue = req.headers .get("Authorization") ?.trim() .replaceAll("Bearer ", "") .trim() ?? ""; + + authHeaderName = "api-key"; } else { - const authValue = req.headers.get("Authorization") ?? ""; + authValue = req.headers.get("Authorization") ?? ""; + authHeaderName = "Authorization"; } - const authHeaderName = serverConfig.isAzure ? "api-key" : "Authorization"; let path = `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll( "/api/openai/",