From c6f022fd5213ced71519f7cdedef993bebd8880e Mon Sep 17 00:00:00 2001 From: qiqi Date: Fri, 6 Dec 2024 12:31:21 +0800 Subject: [PATCH] Compatible for getting auth token from client --- app/api/anthropic.ts | 2 +- app/api/auth.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/api/anthropic.ts b/app/api/anthropic.ts index 7a4444371..2473caa0f 100644 --- a/app/api/anthropic.ts +++ b/app/api/anthropic.ts @@ -62,8 +62,8 @@ async function request(req: NextRequest) { let authHeaderName = "x-api-key"; let authValue = - req.headers.get(authHeaderName) || req.headers.get("Authorization")?.replaceAll("Bearer ", "").trim() || + req.headers.get(authHeaderName) || serverConfig.anthropicApiKey || ""; diff --git a/app/api/auth.ts b/app/api/auth.ts index 6703b64bd..86ec5a4d5 100644 --- a/app/api/auth.ts +++ b/app/api/auth.ts @@ -25,7 +25,8 @@ function parseApiKey(bearToken: string) { } export function auth(req: NextRequest, modelProvider: ModelProvider) { - const authToken = req.headers.get("Authorization") ?? ""; + const authToken = + req.headers.get("Authorization") ?? req.headers.get("x-api-key") ?? ""; // check if it is openai api key or user token const { accessCode, apiKey } = parseApiKey(authToken);