From 7d9a2132cbdafa896ca6523a284d38ec880328b2 Mon Sep 17 00:00:00 2001 From: Fred Liang Date: Sun, 24 Dec 2023 03:57:30 +0800 Subject: [PATCH] fix: fix server token fetch policy --- app/api/google/[...path]/route.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/api/google/[...path]/route.ts b/app/api/google/[...path]/route.ts index 95b1c6418..dcd8a65b0 100644 --- a/app/api/google/[...path]/route.ts +++ b/app/api/google/[...path]/route.ts @@ -45,7 +45,20 @@ async function handle( const bearToken = req.headers.get("Authorization") ?? ""; const token = bearToken.trim().replaceAll("Bearer ", "").trim(); - const key = token ?? serverConfig.googleApiKey; + + const key = token ? token : serverConfig.googleApiKey; + if (!key) { + return NextResponse.json( + { + error: true, + message: `missing GOOGLE_API_KEY in server env vars`, + }, + { + status: 401, + }, + ); + } + const fetchUrl = `${baseUrl}/${path}?key=${key}`; const fetchOptions: RequestInit = {