mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-23 22:20:23 +09:00
fix: gemini authentication error
This commit is contained in:
parent
2a9b36f626
commit
98b5ace66e
@ -28,7 +28,12 @@ export function auth(req: NextRequest, modelProvider: ModelProvider) {
|
|||||||
const authToken = req.headers.get("Authorization") ?? "";
|
const authToken = req.headers.get("Authorization") ?? "";
|
||||||
|
|
||||||
// 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);
|
let { accessCode, apiKey } = parseApiKey(authToken);
|
||||||
|
|
||||||
|
if (modelProvider === ModelProvider.GeminiPro) {
|
||||||
|
const googleAuthToken = req.headers.get("x-goog-api-key") ?? "";
|
||||||
|
apiKey = googleAuthToken.trim().replaceAll("Bearer ", "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
const hashedCode = md5.hash(accessCode ?? "").trim();
|
const hashedCode = md5.hash(accessCode ?? "").trim();
|
||||||
|
|
||||||
|
@ -180,11 +180,7 @@ export function getHeaders(ignoreHeaders?: boolean) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const isAzure = accessStore.provider === ServiceProvider.Azure;
|
const isAzure = accessStore.provider === ServiceProvider.Azure;
|
||||||
const authHeader = isGoogle
|
let authHeader = isAzure ? "api-key" : "Authorization";
|
||||||
? "x-goog-api-key"
|
|
||||||
: isAzure
|
|
||||||
? "api-key"
|
|
||||||
: "Authorization";
|
|
||||||
const apiKey = isGoogle
|
const apiKey = isGoogle
|
||||||
? accessStore.googleApiKey
|
? accessStore.googleApiKey
|
||||||
: isAzure
|
: isAzure
|
||||||
@ -197,6 +193,7 @@ export function getHeaders(ignoreHeaders?: boolean) {
|
|||||||
|
|
||||||
// use user's api key first
|
// use user's api key first
|
||||||
if (validString(apiKey)) {
|
if (validString(apiKey)) {
|
||||||
|
authHeader = isGoogle ? "x-goog-api-key" : authHeader;
|
||||||
headers[authHeader] = makeBearer(apiKey);
|
headers[authHeader] = makeBearer(apiKey);
|
||||||
} else if (
|
} else if (
|
||||||
accessStore.enabledAccessControl() &&
|
accessStore.enabledAccessControl() &&
|
||||||
|
Loading…
Reference in New Issue
Block a user