From 00f61b214c04c5c78380f74898cdd50cbf2ccdd4 Mon Sep 17 00:00:00 2001 From: Achintya Rajan Date: Mon, 6 Oct 2025 14:17:02 -0700 Subject: [PATCH] more window guards --- .../VirtualKeysTable/VirtualKeysTable.tsx | 23 ++++++++++--------- ui/litellm-dashboard/src/utils/cookieUtils.ts | 4 ++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ui/litellm-dashboard/src/app/dashboard/virtual-keys/components/VirtualKeysTable/VirtualKeysTable.tsx b/ui/litellm-dashboard/src/app/dashboard/virtual-keys/components/VirtualKeysTable/VirtualKeysTable.tsx index b7727a299bf..cbf10f97715 100644 --- a/ui/litellm-dashboard/src/app/dashboard/virtual-keys/components/VirtualKeysTable/VirtualKeysTable.tsx +++ b/ui/litellm-dashboard/src/app/dashboard/virtual-keys/components/VirtualKeysTable/VirtualKeysTable.tsx @@ -105,18 +105,19 @@ const VirtualKeysTable = ({ // Add a useEffect to call refresh when a key is created useEffect(() => { - if (refresh) { - const handleStorageChange = () => { - refresh(); - }; - - // Listen for storage events that might indicate a key was created - window.addEventListener("storage", handleStorageChange); - - return () => { - window.removeEventListener("storage", handleStorageChange); - }; + if (!refresh || typeof window === "undefined") { + return; } + const handleStorageChange = () => { + refresh(); + }; + + // Listen for storage events that might indicate a key was created + window.addEventListener("storage", handleStorageChange); + + return () => { + window.removeEventListener("storage", handleStorageChange); + }; }, [refresh]); const columns: ColumnDef[] = [ diff --git a/ui/litellm-dashboard/src/utils/cookieUtils.ts b/ui/litellm-dashboard/src/utils/cookieUtils.ts index e477a9f77e0..23682fd6e81 100644 --- a/ui/litellm-dashboard/src/utils/cookieUtils.ts +++ b/ui/litellm-dashboard/src/utils/cookieUtils.ts @@ -6,6 +6,10 @@ * Clears the token cookie from both root and /ui paths */ export function clearTokenCookies() { + if (typeof window === "undefined" || typeof document === "undefined") { + return; + } + // Get the current domain const domain = window.location.hostname;