From 19137b79bcf17d1b1be01740dd5ed0238c784680 Mon Sep 17 00:00:00 2001 From: Fred Liang Date: Mon, 25 Dec 2023 09:56:51 +0800 Subject: [PATCH] fix: return bearer header when using openai --- app/api/common.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index 8e029c35..a6f4c572 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -9,9 +9,16 @@ const serverConfig = getServerSideConfig(); export async function requestOpenai(req: NextRequest) { const controller = new AbortController(); - const authValue = - req.headers.get("Authorization")?.trim().replaceAll("Bearer ", "").trim() ?? - ""; + if (serverConfig.isAzure) { + const authValue = + req.headers + .get("Authorization") + ?.trim() + .replaceAll("Bearer ", "") + .trim() ?? ""; + } else { + const authValue = req.headers.get("Authorization") ?? ""; + } const authHeaderName = serverConfig.isAzure ? "api-key" : "Authorization"; let path = `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll(