Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

New login screen using v2/login

yuneng-jiangb14b4a711295
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/hooks/login/useLogin.ts b/ui/litellm-dashboard/src/app/(dashboard)/hooks/login/useLogin.ts
index 486d2e39929..a15b4a06d13 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/hooks/login/useLogin.ts
+++ b/ui/litellm-dashboard/src/app/(dashboard)/hooks/login/useLogin.ts
@@ -7,11 +7,5 @@ export const useLogin = () => {
const result = await loginCall(username, password);
return result;
},
- onSuccess: (data) => {
- // Redirect to UI on successful login
- if (data.success && data.redirectUrl) {
- window.location.href = data.redirectUrl;
- }
- },
});
};
diff --git a/ui/litellm-dashboard/src/app/login/page.tsx b/ui/litellm-dashboard/src/app/login/page.tsx
index 4ffe7cbfe80..6248639b063 100644
--- a/ui/litellm-dashboard/src/app/login/page.tsx
+++ b/ui/litellm-dashboard/src/app/login/page.tsx
@@ -1,33 +1,57 @@
"use client";
-import React, { useState } from "react";
-import { Form, Input, Button, Alert, Typography, Card, Spin, Space } from "antd";
+import { useLogin } from "@/app/(dashboard)/hooks/login/useLogin";
+import { useUIConfig } from "@/app/(dashboard)/hooks/uiConfig/useUIConfig";
+import LoadingScreen from "@/components/common_components/LoadingScreen";
+import { getProxyBaseUrl } from "@/components/networking";
+import { getCookie } from "@/utils/cookieUtils";
+import { isJwtExpired } from "@/utils/jwtUtils";
import { InfoCircleOutlined } from "@ant-design/icons";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { useUIConfig } from "@/app/(dashboard)/hooks/uiConfig/useUIConfig";
-import { useLogin } from "@/app/(dashboard)/hooks/login/useLogin";
+import { Alert, Button, Card, Form, Input, Space, Typography } from "antd";
+import { useRouter } from "next/navigation";
+import { useEffect, useState } from "react";
function LoginPageContent() {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
+ const [isLoading, setIsLoading] = useState(true);
const { isLoading: isConfigLoading } = useUIConfig();
const loginMutation = useLogin();
+ const router = useRouter();
+
+ useEffect(() => {
+ if (isConfigLoading) {
+ return;
+ }
- const handleSubmit = async () => {
- loginMutation.mutate({ username, password });
+ const rawToken = getCookie("token");
+ if (rawToken && !isJwtExpired(rawToken)) {
+ router.replace(`${getProxyBaseUrl()}/ui`);
+ return;
+ }
+
+ setIsLoading(false);
+ }, [isConfigLoading, router]);
+
+ const handleSubmit = () => {
+ loginMutation.mutate(
+ { username, password },
+ {
+ onSuccess: (data) => {
+ router.push(data.redirect_url);
+ },
+ },
+ );
};
const error = loginMutation.error instanceof Error ? loginMutation.error.message : null;
- const isLoading = loginMutation.isPending;
+ const isLoginLoading = loginMutation.isPending;
const { Title, Text, Paragraph } = Typography;
- if (isConfigLoading) {
- return (
- <div className="flex justify-center items-center min-h-screen">
- <Spin size="large" tip="Loading..." />
- </div>
- );
+ if (isConfigLoading || isLoading) {
+ return <LoadingScreen />;
}
return (
@@ -79,7 +103,7 @@ function LoginPageContent() {
autoComplete="username"
value={username}
onChange={(e) => setUsername(e.target.value)}
- disabled={isLoading}
+ disabled={isLoginLoading}
size="large"
className="rounded-md border-gray-300"
/>
@@ -95,14 +119,21 @@ function LoginPageContent() {
autoComplete="current-password"
value={password}
onChange={(e) => setPassword(e.target.value)}
- disabled={isLoading}
+ disabled={isLoginLoading}
size="large"
/>
</Form.Item>
<Form.Item>
- <Button type="primary" htmlType="submit" loading={isLoading} disabled={isLoading} block size="large">
- {isLoading ? "Logging in..." : "Login"}
+ <Button
+ type="primary"
+ htmlType="submit"
+ loading={isLoginLoading}
+ disabled={isLoginLoading}
+ block
+ size="large"
+ >
+ {isLoginLoading ? "Loggin in..." : "Login"}
</Button>
</Form.Item>
</Form>
diff --git a/ui/litellm-dashboard/src/app/page.tsx b/ui/litellm-dashboard/src/app/page.tsx
index a71d7dd87d3..68060ae6968 100644
--- a/ui/litellm-dashboard/src/app/page.tsx
+++ b/ui/litellm-dashboard/src/app/page.tsx
@@ -1,49 +1,47 @@
"use client";
-import React, { Suspense, useEffect, useState } from "react";
-import { useSearchParams } from "next/navigation";
-import { jwtDecode } from "jwt-decode";
-import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
-import { Team } from "@/components/key_team_helpers/key_list";
-import Navbar from "@/components/navbar";
-import { ThemeProvider } from "@/contexts/ThemeContext";
-import UserDashboard from "@/components/user_dashboard";
+import APIReferenceView from "@/app/(dashboard)/api-reference/APIReferenceView";
+import SidebarProvider from "@/app/(dashboard)/components/SidebarProvider";
import OldModelDashboard from "@/app/(dashboard)/models-and-endpoints/ModelsAndEndpointsView";
-import ViewUserDashboard from "@/components/view_users";
-import Organizations from "@/components/organizations";
-import { fetchOrganizations } from "@/components/organizations";
+import PlaygroundPage from "@/app/(dashboard)/playground/page";
import AdminPanel from "@/components/admins";
-import Settings from "@/components/settings";
-import GeneralSettings from "@/components/general_settings";
-import PassThroughSettings from "@/components/pass_through_settings";
+import AgentsPanel from "@/components/agents";
import BudgetPanel from "@/components/budgets/budget_panel";
-import SpendLogsTable from "@/components/view_logs";
-import ModelHubTable from "@/components/model_hub_table";
-import PublicModelHub from "@/components/public_model_hub";
-import NewUsagePage from "@/components/new_usage";
-import APIReferenceView from "@/app/(dashboard)/api-reference/APIReferenceView";
-import PlaygroundPage from "@/app/(dashboard)/playground/page";
-import Usage from "@/components/usage";
import CacheDashboard from "@/components/cache_dashboard";
-import { getUiConfig, proxyBaseUrl, setGlobalLitellmHeaderName } from "@/components/networking";
-import { Organization } from "@/components/networking";
-import GuardrailsPanel from "@/components/guardrails";
-import AgentsPanel from "@/components/agents";
-import PromptsPanel from "@/components/prompts";
-import TransformRequestPanel from "@/components/transform_request";
-import { fetchUserModels } from "@/components/organisms/create_key_button";
import { fetchTeams } from "@/components/common_components/fetch_teams";
-import { MCPServers } from "@/components/mcp_tools";
-import TagManagement from "@/components/tag_management";
-import VectorStoreManagement from "@/components/vector_store_management";
-import UIThemeSettings from "@/components/ui_theme_settings";
+import LoadingScreen from "@/components/common_components/LoadingScreen";
import { CostTrackingSettings } from "@/components/CostTrackingSettings";
-import { UiLoadingSpinner } from "@/components/ui/ui-loading-spinner";
-import { cx } from "@/lib/cva.config";
-import SidebarProvider from "@/app/(dashboard)/components/SidebarProvider";
+import GeneralSettings from "@/components/general_settings";
+import GuardrailsPanel from "@/components/guardrails";
+import { Team } from "@/components/key_team_helpers/key_list";
+import { MCPServers } from "@/components/mcp_tools";
+import ModelHubTable from "@/components/model_hub_table";
+import Navbar from "@/components/navbar";
+import { getUiConfig, Organization, proxyBaseUrl, setGlobalLitellmHeaderName } from "@/components/networking";
+import NewUsagePage from "@/components/new_usage";
import OldTeams from "@/components/OldTeams";
+import { fetchUserModels } from "@/components/organisms/create_key_button";
+import Organizations, { fetchOrganizations } from "@/components/organizations";
+import PassThroughSettings from "@/components/pass_through_settings";
+import PromptsPanel from "@/components/prompts";
+import PublicModelHub from "@/components/public_model_hub";
import { SearchTools } from "@/components/search_tools";
+import Settings from "@/components/settings";
+import TagManagement from "@/components/tag_management";
+import TransformRequestPanel from "@/components/transform_request";
+import UIThemeSettings from "@/components/ui_theme_settings";
+import Usage from "@/components/usage";
+import UserDashboard from "@/components/user_dashboard";
+import VectorStoreManagement from "@/components/vector_store_management";
+import SpendLogsTable from "@/components/view_logs";
+import ViewUserDashboard from "@/components/view_users";
+import { ThemeProvider } from "@/contexts/ThemeContext";
+import { isJwtExpired } from "@/utils/jwtUtils";
import { isAdminRole } from "@/utils/roles";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { jwtDecode } from "jwt-decode";
+import { useSearchParams } from "next/navigation";
+import { Suspense, useEffect, useState } from "react";
function getCookie(name: string) {
// Safer cookie read + decoding; handles '=' inside values
@@ -62,19 +60,6 @@ function deleteCookie(name: string, path = "/") {
document.cookie = `${name}=; Max-Age=0; Path=${path}`;
}
-function isJwtExpired(token: string): boolean {
- try {
- const decoded: any = jwtDecode(token);
- if (decoded && typeof decoded.exp === "number") {
- return decoded.exp * 1000 <= Date.now();
- }
- return false;
- } catch {
- // If we can't decode, treat as invalid/expired
- return true;
- }
-}
-
function formatUserRole(userRole: string) {
if (!userRole) {
return "Undefined Role";
@@ -112,19 +97,6 @@ interface ProxySettings {
const queryClient = new QueryClient();
-function LoadingScreen() {
- return (
- <div className={cx("h-screen", "flex items-center justify-center gap-4")}>
- <div className="text-lg font-medium py-2 pr-4 border-r border-r-gray-200">🚅 LiteLLM</div>
-
- <div className="flex items-center justify-center gap-2">
- <UiLoadingSpinner className="size-4" />
- <span className="text-gray-600 text-sm">Loading...</span>
- </div>
- </div>
- );
-}
-
export default function CreateKeyPage() {
const [userRole, setUserRole] = useState("");
const [premiumUser, setPremiumUser] = useState(false);
diff --git a/ui/litellm-dashboard/src/components/common_components/LoadingScreen.test.tsx b/ui/litellm-dashboard/src/components/common_components/LoadingScreen.test.tsx
new file mode 100644
index 00000000000..5601c53d574
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/common_components/LoadingScreen.test.tsx
@@ -0,0 +1,10 @@
+import { render, screen } from "@testing-library/react";
+import { describe, it, expect } from "vitest";
+import LoadingScreen from "./LoadingScreen";
+
+describe("LoadingScreen", () => {
+ it("should render", () => {
+ render(<LoadingScreen />);
+ expect(screen.getByText("Loading...")).toBeInTheDocument();
+ });
+});
diff --git a/ui/litellm-dashboard/src/components/common_components/LoadingScreen.tsx b/ui/litellm-dashboard/src/components/common_components/LoadingScreen.tsx
new file mode 100644
index 00000000000..6144fa6aad1
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/common_components/LoadingScreen.tsx
@@ -0,0 +1,15 @@
+import { cx } from "@/lib/cva.config";
+import { UiLoadingSpinner } from "../ui/ui-loading-spinner";
+
+export default function LoadingScreen() {
+ return (
+ <div className={cx("h-screen", "flex items-center justify-center gap-4")}>
+ <div className="text-lg font-medium py-2 pr-4 border-r border-r-gray-200">🚅 LiteLLM</div>
+
+ <div className="flex items-center justify-center gap-2">
+ <UiLoadingSpinner className="size-4" />
+ <span className="text-gray-600 text-sm">Loading...</span>
+ </div>
+ </div>
+ );
+}
diff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsx
index 76b79c0f8b8..061d62d6700 100644
--- a/ui/litellm-dashboard/src/components/networking.tsx
+++ b/ui/litellm-dashboard/src/components/networking.tsx
@@ -7980,51 +7980,33 @@ export interface LoginRequest {
}
export interface LoginResponse {
- success: boolean;
- redirectUrl?: string;
+ redirect_url: string;
}
export const loginCall = async (username: string, password: string): Promise<LoginResponse> => {
const proxyBaseUrl = getProxyBaseUrl();
- const loginUrl = proxyBaseUrl ? `${proxyBaseUrl}/login` : "/login";
+ const loginUrl = proxyBaseUrl ? `${proxyBaseUrl}/v2/login` : "/v2/login";
- const formData = new FormData();
- formData.append("username", username);
- formData.append("password", password);
+ const body = JSON.stringify({
+ username,
+ password,
+ });
const response = await fetch(loginUrl, {
method: "POST",
- body: formData,
+ body,
credentials: "include",
- redirect: "manual",
+ headers: {
+ "Content-Type": "application/json",
+ },
});
- // Handle redirect status codes (301, 302, 303, 307, 308)
- if (response.status >= 300 && response.status < 400) {
- const redirectUrl = response.headers.get("Location");
-
- if (!redirectUrl) {
- throw new Error("Login redirect missing Location header");
- }
-
- return {
- success: true,
- redirectUrl,
- };
- }
-
- if (response.ok) {
- return {
- success: true,
- redirectUrl: "/uia/",
- };
+ if (!response.ok) {
+ const errorData = await response.json();
+ const errorMessage = deriveErrorMessage(errorData);
+ throw new Error(errorMessage);
}
- // Otherwise, try to extract an error
- let errorText = "Invalid username or password";
- try {
- errorText = await response.text();
- } catch {}
-
- throw new Error(errorText || "Login failed");
+ const data = await response.json();
+ return data;
};
diff --git a/ui/litellm-dashboard/src/utils/jwtUtils.test.ts b/ui/litellm-dashboard/src/utils/jwtUtils.test.ts
new file mode 100644
index 00000000000..d695a3c37bb
--- /dev/null
+++ b/ui/litellm-dashboard/src/utils/jwtUtils.test.ts
@@ -0,0 +1,53 @@
+import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
+import { isJwtExpired } from "./jwtUtils";
+import { jwtDecode } from "jwt-decode";
+
+vi.mock("jwt-decode");
+
+describe("jwtUtils", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ it("should return true if the token is expired", () => {
+ const mockDateNow = 1716838401000;
+ vi.spyOn(Date, "now").mockReturnValue(mockDateNow);
+ vi.mocked(jwtDecode).mockReturnValue({
+ exp: Math.floor(mockDateNow / 1000) - 1,
+ user_id: "test",
+ });
+
+ expect(isJwtExpired("any-token")).toBe(true);
+ });
+
+ it("should return false if the token is not expired", () => {
+ const mockDateNow = 1716838401000;
+ vi.spyOn(Date, "now").mockReturnValue(mockDateNow);
+ vi.mocked(jwtDecode).mockReturnValue({
+ exp: Math.floor(mockDateNow / 1000) + 1000,
+ user_id: "test",
+ });
+
+ expect(isJwtExpired("any-token")).toBe(false);
+ });
+
+ it("should return false if the token does not have an exp field", () => {
+ vi.mocked(jwtDecode).mockReturnValue({
+ user_id: "test",
+ });
+
+ expect(isJwtExpired("any-token")).toBe(false);
+ });
+
+ it("should return true if jwtDecode throws an error", () => {
+ vi.mocked(jwtDecode).mockImplementation(() => {
+ throw new Error("Invalid token");
+ });
+
+ expect(isJwtExpired("invalid-token")).toBe(true);
+ });
+});
diff --git a/ui/litellm-dashboard/src/utils/jwtUtils.ts b/ui/litellm-dashboard/src/utils/jwtUtils.ts
new file mode 100644
index 00000000000..d3db41a411a
--- /dev/null
+++ b/ui/litellm-dashboard/src/utils/jwtUtils.ts
@@ -0,0 +1,14 @@
+import { jwtDecode } from "jwt-decode";
+
+export function isJwtExpired(token: string): boolean {
+ try {
+ const decoded: any = jwtDecode(token);
+ if (decoded && typeof decoded.exp === "number") {
+ return decoded.exp * 1000 <= Date.now();
+ }
+ return false;
+ } catch {
+ // If we can't decode, treat as invalid/expired
+ return true;
+ }
+}