From 7326682c94d1a68e99a458c99ad241cbc4a62733 Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Fri, 21 Feb 2025 09:37:36 -0800 Subject: [PATCH] Watch for empty cookie strings --- app/components/chat/Chat.client.tsx | 4 +++- app/lib/replay/Problems.ts | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index b5bb7eff..76f15a33 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -336,7 +336,9 @@ export const ChatImpl = memo( } const loginKey = getNutLoginKey(); - const anthropicApiKey = Cookies.get(anthropicApiKeyCookieName); + + const apiKeyCookie = Cookies.get(anthropicApiKeyCookieName); + const anthropicApiKey = apiKeyCookie?.length ? apiKeyCookie : undefined; if (!loginKey && !anthropicApiKey) { const numFreeUses = +(Cookies.get(anthropicNumFreeUsesCookieName) || 0); diff --git a/app/lib/replay/Problems.ts b/app/lib/replay/Problems.ts index 45d7aaa1..e3289514 100644 --- a/app/lib/replay/Problems.ts +++ b/app/lib/replay/Problems.ts @@ -134,7 +134,8 @@ const nutLoginKeyCookieName = 'nutLoginKey'; const nutIsAdminCookieName = 'nutIsAdmin'; export function getNutLoginKey(): string | undefined { - return Cookies.get(nutLoginKeyCookieName); + const cookieValue = Cookies.get(nutLoginKeyCookieName); + return cookieValue?.length ? cookieValue : undefined; } export function getNutIsAdmin(): boolean { @@ -169,7 +170,8 @@ export function setNutIsAdmin(isAdmin: boolean) { const nutProblemsUsernameCookieName = 'nutProblemsUsername'; export function getProblemsUsername(): string | undefined { - return Cookies.get(nutProblemsUsernameCookieName); + const cookieValue = Cookies.get(nutProblemsUsernameCookieName); + return cookieValue?.length ? cookieValue : undefined; } export function saveProblemsUsername(username: string) {