From 4e508ce03502f3bab13f49c483f4536cda0371c7 Mon Sep 17 00:00:00 2001 From: Scott Griffin <35553625+CambodianCoder@users.noreply.github.com> Date: Thu, 25 Jun 2026 15:36:25 -0600 Subject: [PATCH] Reorder API key validation logic Checks for apiKey existence before calling startsWith on a potentially undefined field. --- src/web/_web_auth.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/web/_web_auth.ts b/src/web/_web_auth.ts index 8522404b0a..521abf1faa 100644 --- a/src/web/_web_auth.ts +++ b/src/web/_web_auth.ts @@ -17,14 +17,16 @@ export class WebAuth implements Auth { return; } - if (this.apiKey.startsWith('auth_tokens/')) { - throw new Error('Ephemeral tokens are only supported by the live API.'); - } - // Check if API key is empty or null if (!this.apiKey) { throw new Error('API key is missing. Please provide a valid API key.'); } + + if (this.apiKey.startsWith('auth_tokens/')) { + throw new Error('Ephemeral tokens are only supported by the live API.'); + } + + headers.append(GOOGLE_API_KEY_HEADER, this.apiKey); } }