From e4d2d77f11f83f62b1d4730a1763235fff25a6ab Mon Sep 17 00:00:00 2001 From: ishaan-jaff Date: Wed, 31 Jan 2024 18:12:03 -0800 Subject: [PATCH] (ui) use jwt for accessToken --- .../src/components/user_dashboard.tsx | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ui/litellm-dashboard/src/components/user_dashboard.tsx b/ui/litellm-dashboard/src/components/user_dashboard.tsx index f66d39fba..8a049de4c 100644 --- a/ui/litellm-dashboard/src/components/user_dashboard.tsx +++ b/ui/litellm-dashboard/src/components/user_dashboard.tsx @@ -6,14 +6,32 @@ import CreateKey from "./create_key_button"; import ViewKeyTable from "./view_key_table"; import EnterProxyUrl from "./enter_proxy_url"; import { useSearchParams } from "next/navigation"; +import { jwtDecode } from "jwt-decode"; const UserDashboard = () => { const [data, setData] = useState(null); // Keep the initialization of state here // Assuming useSearchParams() hook exists and works in your setup const searchParams = useSearchParams(); const userID = searchParams.get("userID"); - const accessToken = searchParams.get("accessToken"); const proxyBaseUrl = searchParams.get("proxyBaseUrl"); + const token = searchParams.get("token"); + let accessToken = ""; + + useEffect(() => { + if (token){ + const decoded = jwtDecode(token) as { [key: string]: any }; + if (decoded) { + // cast decoded to dictionary + console.log("Decoded token:", decoded); + + console.log("Decoded key:", decoded.key); + // set accessToken + accessToken = decoded.key + } + + + } + }, [token]); // Moved useEffect inside the component and used a condition to run fetch only if the params are available useEffect(() => { @@ -34,7 +52,6 @@ const UserDashboard = () => { fetchData(); } }, [userID, accessToken, proxyBaseUrl, data]); - if (proxyBaseUrl == null) { return (
@@ -50,7 +67,6 @@ const UserDashboard = () => { window.location.href = url; - return null; }