mirror of
https://github.com/ChatGPTNextWeb/NextChat.git
synced 2026-03-03 00:25:02 +08:00
feat: add multi-model support
This commit is contained in:
28
app/client/common/auth.ts
Normal file
28
app/client/common/auth.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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 getAuthHeaders(apiKey = "") {
|
||||
const accessStore = useAccessStore.getState();
|
||||
const isApp = !!getClientConfig()?.isApp;
|
||||
|
||||
let headers: Record<string, string> = {};
|
||||
|
||||
if (apiKey) {
|
||||
// use user's api key first
|
||||
headers.Authorization = bearer(apiKey);
|
||||
} else if (
|
||||
accessStore.enabledAccessControl() &&
|
||||
!isApp &&
|
||||
!!accessStore.accessCode
|
||||
) {
|
||||
// or use access code
|
||||
headers.Authorization = bearer(ACCESS_CODE_PREFIX + accessStore.accessCode);
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
Reference in New Issue
Block a user