mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-06-01 10:20:26 +09:00
fix: 1. anthropic client using common getHeaders; 2. always using Authorization
header send access code
This commit is contained in:
parent
d65ddead11
commit
37e2517dac
@ -184,7 +184,8 @@ export function getHeaders() {
|
|||||||
accessStore.enabledAccessControl() &&
|
accessStore.enabledAccessControl() &&
|
||||||
validString(accessStore.accessCode)
|
validString(accessStore.accessCode)
|
||||||
) {
|
) {
|
||||||
headers[authHeader] = makeBearer(
|
// access_code must send with header named `Authorization`, will using in auth middleware.
|
||||||
|
headers['Authorization'] = makeBearer(
|
||||||
ACCESS_CODE_PREFIX + accessStore.accessCode,
|
ACCESS_CODE_PREFIX + accessStore.accessCode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,8 @@ export class ClaudeApi implements LLMApi {
|
|||||||
headers: {
|
headers: {
|
||||||
...getHeaders(), // get common headers
|
...getHeaders(), // get common headers
|
||||||
"anthropic-version": accessStore.anthropicApiVersion,
|
"anthropic-version": accessStore.anthropicApiVersion,
|
||||||
Authorization: getAuthKey(accessStore.anthropicApiKey),
|
// do not send `anthropicApiKey` in browser!!!
|
||||||
|
// Authorization: getAuthKey(accessStore.anthropicApiKey),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -387,27 +388,3 @@ function trimEnd(s: string, end = " ") {
|
|||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bearer(value: string) {
|
|
||||||
return `Bearer ${value.trim()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getAuthKey(apiKey = "") {
|
|
||||||
const accessStore = useAccessStore.getState();
|
|
||||||
const isApp = !!getClientConfig()?.isApp;
|
|
||||||
let authKey = "";
|
|
||||||
|
|
||||||
if (apiKey) {
|
|
||||||
// use user's api key first
|
|
||||||
authKey = bearer(apiKey);
|
|
||||||
} else if (
|
|
||||||
accessStore.enabledAccessControl() &&
|
|
||||||
!isApp &&
|
|
||||||
!!accessStore.accessCode
|
|
||||||
) {
|
|
||||||
// or use access code
|
|
||||||
authKey = bearer(ACCESS_CODE_PREFIX + accessStore.accessCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
return authKey;
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user