mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-25 07:00:23 +09:00
28 lines
690 B
TypeScript
28 lines
690 B
TypeScript
import { getClientConfig } from "@/app/config/client";
|
|
import { ACCESS_CODE_PREFIX } from "@/app/constant";
|
|
import { useAccessStore } from "@/app/store";
|
|
|
|
export function bearer(value: string) {
|
|
return `Bearer ${value.trim()}`;
|
|
}
|
|
|
|
export 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;
|
|
}
|