From 9bfd979b08c38be30861cb7b370e993b7dedfe61 Mon Sep 17 00:00:00 2001 From: Fred Liang Date: Mon, 25 Dec 2023 10:25:43 +0800 Subject: [PATCH] chore: update auth value logic (#3630) --- app/api/common.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index 3031edfac73..9565a7a0a25 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -9,7 +9,8 @@ const serverConfig = getServerSideConfig(); export async function requestOpenai(req: NextRequest) { const controller = new AbortController(); - let authValue = req.headers.get("Authorization") ?? ""; + var authValue, + authHeaderName = ""; if (serverConfig.isAzure) { authValue = req.headers @@ -17,8 +18,12 @@ export async function requestOpenai(req: NextRequest) { ?.trim() .replaceAll("Bearer ", "") .trim() ?? ""; + + authHeaderName = "api-key"; + } else { + 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/",