From 35471a41c89cdfdd2b6a59c25b24d415049556fc Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 25 Dec 2023 00:30:23 +0700 Subject: [PATCH] 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 --- app/api/auth.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/api/auth.ts b/app/api/auth.ts index b41e34e0..043ad0d3 100644 --- a/app/api/auth.ts +++ b/app/api/auth.ts @@ -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");