mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-01 15:46:39 +08:00
Compatible for getting auth token from client
This commit is contained in:
parent
83cea3a90d
commit
c6f022fd52
@ -62,8 +62,8 @@ async function request(req: NextRequest) {
|
|||||||
|
|
||||||
let authHeaderName = "x-api-key";
|
let authHeaderName = "x-api-key";
|
||||||
let authValue =
|
let authValue =
|
||||||
req.headers.get(authHeaderName) ||
|
|
||||||
req.headers.get("Authorization")?.replaceAll("Bearer ", "").trim() ||
|
req.headers.get("Authorization")?.replaceAll("Bearer ", "").trim() ||
|
||||||
|
req.headers.get(authHeaderName) ||
|
||||||
serverConfig.anthropicApiKey ||
|
serverConfig.anthropicApiKey ||
|
||||||
"";
|
"";
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user