Compatible for getting auth token from client

This commit is contained in:
qiqi 2024-12-06 12:31:21 +08:00
parent 83cea3a90d
commit 54080c0563

View File

@ -25,7 +25,8 @@ function parseApiKey(bearToken: string) {
} }
export function auth(req: NextRequest, modelProvider: ModelProvider) { 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 // check if it is openai api key or user token
const { accessCode, apiKey } = parseApiKey(authToken); const { accessCode, apiKey } = parseApiKey(authToken);