From 55e4ec14ab1238d470afcf3969240fd2eefcf207 Mon Sep 17 00:00:00 2001 From: Kerry Lu Date: Mon, 16 Nov 2026 20:56:57 -0800 Subject: [PATCH] fix(ui): use full page navigation for SSO login (#52213) * fix(ui): use full page navigation for SSO login * style(ui): format SSO navigation regression test --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../src/app/login/LoginPage.test.tsx | 60 ++++++++++++------- .../src/app/login/LoginPage.tsx | 8 +-- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/litellm/ui/litellm-dashboard/src/app/login/LoginPage.test.tsx b/litellm/ui/litellm-dashboard/src/app/login/LoginPage.test.tsx index f51a86c3102..ee427c5ae70 100644 --- a/litellm/ui/litellm-dashboard/src/app/login/LoginPage.test.tsx +++ b/litellm/ui/litellm-dashboard/src/app/login/LoginPage.test.tsx @@ -142,31 +142,40 @@ describe("LoginPage", () => { }); }); - it("should call router.push to SSO when jwt is invalid and auto_redirect_to_sso is true", async () => { - const invalidToken = "invalid-token"; - (useUIConfig as ReturnType).mockReturnValue({ - data: { - auto_redirect_to_sso: true, - server_root_path: "/", - proxy_base_url: null, - sso_configured: true, - }, - isLoading: false, - }); - (getCookieFromDocument as ReturnType).mockReturnValue(invalidToken); - (isJwtExpired as ReturnType).mockReturnValue(true); + it.each([null, "/ui/?page=usage"])( + "navigates the document to SSO automatically with return URL %s", + async (returnUrl) => { + if (returnUrl) { + document.cookie = `litellm_return_url=${encodeURIComponent(returnUrl)}; Path=/`; + } + const invalidToken = "invalid-token"; + (useUIConfig as ReturnType).mockReturnValue({ + data: { + auto_redirect_to_sso: true, + server_root_path: "/", + proxy_base_url: null, + sso_configured: true, + }, + isLoading: false, + }); + (getCookieFromDocument as ReturnType).mockReturnValue(invalidToken); + (isJwtExpired as ReturnType).mockReturnValue(true); - const queryClient = createQueryClient(); - render( - - - , - ); + const queryClient = createQueryClient(); + render( + + + , + ); - await waitFor(() => { - expect(mockPush).toHaveBeenCalledWith("http://localhost:4000/sso/key/generate"); - }); - }); + await waitFor(() => { + expect(mockAssignDocument).toHaveBeenCalledWith( + `http://localhost:4000/sso/key/generate${returnUrl ? `?redirect_to=${encodeURIComponent(returnUrl)}` : ""}`, + ); + }); + expect(mockPush).not.toHaveBeenCalled(); + }, + ); it("should not call router when jwt is invalid and auto_redirect_to_sso is false", async () => { const invalidToken = "invalid-token"; @@ -278,6 +287,11 @@ describe("LoginPage", () => { }); expect(screen.getByRole("button", { name: "Login with SSO" })).toBeInTheDocument(); + fireEvent.click(screen.getByRole("button", { name: "Login with SSO" })); + expect(mockAssignDocument).toHaveBeenCalledWith( + `http://localhost:4000/sso/key/generate?return_to=${encodeURIComponent(`${window.location.origin}/ui/login/`)}`, + ); + expect(mockPush).not.toHaveBeenCalled(); }); it("should show disabled Login with SSO button with popover when sso_configured is false", async () => { diff --git a/litellm/ui/litellm-dashboard/src/app/login/LoginPage.tsx b/litellm/ui/litellm-dashboard/src/app/login/LoginPage.tsx index ec0594fafb8..a154a3e3943 100644 --- a/litellm/ui/litellm-dashboard/src/app/login/LoginPage.tsx +++ b/litellm/ui/litellm-dashboard/src/app/login/LoginPage.tsx @@ -25,7 +25,6 @@ import { isJwtExpired } from "@/utils/jwtUtils"; import { consumeReturnUrl, getLoginUrl, getReturnUrl, isValidReturnUrl } from "@/utils/returnUrlUtils"; import { navigateToUiPage } from "@/utils/uiNavigation"; import { CircleAlert, Info, TriangleAlert, X } from "lucide-react"; -import { useRouter } from "next/navigation"; import { useEffect, useId, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { z } from "zod"; @@ -80,7 +79,6 @@ function LoginPageContent() { const [isLoading, setIsLoading] = useState(true); const { data: uiConfig, isLoading: isConfigLoading } = useUIConfig(); const loginMutation = useLogin(); - const router = useRouter(); const { workers, selectWorker } = useWorker(); const [selectedWorkerId, setSelectedWorkerId] = useState(null); const workerFieldId = useId(); @@ -149,12 +147,12 @@ function LoginPageContent() { if (returnUrl && isValidReturnUrl(returnUrl)) { ssoUrl += `?redirect_to=${encodeURIComponent(returnUrl)}`; } - router.push(ssoUrl); + window.location.assign(ssoUrl); return; } setIsLoading(false); - }, [isConfigLoading, router, uiConfig]); + }, [isConfigLoading, uiConfig]); const handleSubmit = ({ username, password }: LoginFormValues) => { // If a worker is selected, point proxyBaseUrl at it before login @@ -355,7 +353,7 @@ function LoginPageContent() { // include return_to so the callback redirects back here const ssoBase = selectedWorker?.url ?? getProxyBaseUrl(); const returnTo = encodeURIComponent(getLoginUrl(window.location.origin)); - router.push(`${ssoBase}/sso/key/generate?return_to=${returnTo}`); + window.location.assign(`${ssoBase}/sso/key/generate?return_to=${returnTo}`); }} className="w-full" >