From 08f7c188fdbae2c78b118e3253ee322251ecb4ab Mon Sep 17 00:00:00 2001 From: ryan-crabbe-berri Date: Tue, 9 Jun 2026 17:30:23 -0700 Subject: [PATCH] refactor(ui): trim auth comments to logic that isn't self-evident --- .../src/app/(dashboard)/hooks/useAuthorized.ts | 10 ++-------- ui/litellm-dashboard/src/contexts/AuthContext.tsx | 6 ++---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/useAuthorized.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/useAuthorized.ts index c256c7466b3..0ef5392667e 100644 --- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/useAuthorized.ts +++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/useAuthorized.ts @@ -7,16 +7,10 @@ import { useCallback, useEffect } from "react"; import { useAuth } from "@/contexts/AuthContext"; import { useUIConfig } from "./uiConfig/useUIConfig"; -// Decoded-JWT fields keep the pre-consolidation `any` typing: the old hook returned -// `any` here and ~25 call sites pass these where `string` is expected. Tightening to -// the context's `string | null` is a follow-up that has to fix those call sites. +// Decoded-JWT fields keep their legacy `any` typing; call sites still pass them +// where `string` is expected, so tightening to `string | null` is a follow-up. type LegacyDecodedField = any; -/** - * Policy hook for pages that require an authenticated user. Auth state itself - * lives in AuthContext (single decode at the root); this hook layers on the - * admin_ui_disabled check and the redirect-to-login side effect. - */ const useAuthorized = () => { const router = useRouter(); const { data: uiConfig, isLoading: isUIConfigLoading } = useUIConfig(); diff --git a/ui/litellm-dashboard/src/contexts/AuthContext.tsx b/ui/litellm-dashboard/src/contexts/AuthContext.tsx index 623f7224785..61152d793f1 100644 --- a/ui/litellm-dashboard/src/contexts/AuthContext.tsx +++ b/ui/litellm-dashboard/src/contexts/AuthContext.tsx @@ -77,10 +77,8 @@ export function AuthProvider({ children }: { children: React.ReactNode }) { }; }, []); - // Side effects of a token change: drop tokens that fail to decode, sync the - // mutable user fields, and apply any custom auth header. The reset branch runs - // after any commit that nulls the token, so user fields cannot survive clearAuth - // even if a stale sync was queued in the same commit. + // Sync the mutable user fields and the custom auth header to the decoded token; + // a token that fails to decode is cleared. useEffect(() => { if (token && !decoded) { clearAuth();