From 2ea7b975c241101cdfbf24546a825c29b21121bb Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 3 Mar 2025 14:56:40 -0800 Subject: [PATCH] add cookieUtils --- ui/litellm-dashboard/src/utils/cookieUtils.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 ui/litellm-dashboard/src/utils/cookieUtils.ts diff --git a/ui/litellm-dashboard/src/utils/cookieUtils.ts b/ui/litellm-dashboard/src/utils/cookieUtils.ts new file mode 100644 index 00000000000..3e8d49b51cf --- /dev/null +++ b/ui/litellm-dashboard/src/utils/cookieUtils.ts @@ -0,0 +1,28 @@ +/** + * Utility functions for managing cookies + */ + +/** + * Clears the token cookie from both root and /ui paths + */ +export function clearTokenCookies() { + // Clear token cookie on root path + document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; + + // Clear token cookie on /ui path + document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/ui;"; + + console.log("After clearing cookies:", document.cookie); +} + +/** + * Gets a cookie value by name + * @param name The name of the cookie to retrieve + * @returns The cookie value or null if not found + */ +export function getCookie(name: string) { + const cookieValue = document.cookie + .split('; ') + .find(row => row.startsWith(name + '=')); + return cookieValue ? cookieValue.split('=')[1] : null; +} \ No newline at end of file