From c1912736f0de24830a60b6f1af395551365fe1f7 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 25 Dec 2023 04:39:04 +0700 Subject: [PATCH] [cherry pick] fix: fix removing bearer header (#202) Co-authored-by: fredliang44 --- app/api/auth.ts | 6 ------ app/api/common.ts | 4 +++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/app/api/auth.ts b/app/api/auth.ts index da97489b48f..d5cef4efe7f 100644 --- a/app/api/auth.ts +++ b/app/api/auth.ts @@ -63,12 +63,6 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) { if (!apiKey) { const serverConfig = getServerSideConfig(); - // const systemApiKey = serverConfig.isAzure - // ? serverConfig.azureApiKey - // : serverConfig.isGoogle - // ? serverConfig.googleApiKey - // : serverConfig.apiKey; - const systemApiKey = modelProvider === ModelProvider.GeminiPro ? serverConfig.googleApiKey diff --git a/app/api/common.ts b/app/api/common.ts index 5520e201d50..93e306e36de 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -9,7 +9,9 @@ const serverConfig = getServerSideConfig(); export async function requestOpenai(req: NextRequest) { const controller = new AbortController(); - const authValue = req.headers.get("Authorization") ?? ""; + const authValue = + req.headers.get("Authorization")?.trim().replaceAll("Bearer ", "").trim() ?? + ""; const authHeaderName = serverConfig.isAzure ? "api-key" : "Authorization"; let path = `${req.nextUrl.pathname}${req.nextUrl.search}`.replaceAll(