Fix & Feat [Auth] Api Key Variable

- [+] fix(auth.ts): fix variable name from serverApiKey to systemApiKey
- [+] feat(auth.ts): add support for Google API key in addition to Azure API key
This commit is contained in:
H0llyW00dzZ 2023-12-25 00:30:23 +07:00
parent bda3098a31
commit 35471a41c8
No known key found for this signature in database
GPG Key ID: 05C7FFFC0845C930

View File

@ -55,15 +55,18 @@ export function auth(req: NextRequest) {
// if user does not provide an api key, inject system api key
if (!apiKey) {
const serverApiKey = serverConfig.isAzure
const serverConfig = getServerSideConfig();
const systemApiKey = serverConfig.isAzure
? serverConfig.azureApiKey
: serverConfig.isGoogle
? serverConfig.googleApiKey
: serverConfig.apiKey;
if (serverApiKey) {
if (systemApiKey) {
console.log("[Auth] use system api key");
req.headers.set(
"Authorization",
`${serverConfig.isAzure ? "" : "Bearer "}${serverApiKey}`,
`Bearer ${systemApiKey}`,
);
} else {
console.log("[Auth] admin did not provide an api key");