fix(admins.tsx): fix logic for getting base url and create common get base url component (#7854)

Resolves https://github.com/BerriAI/litellm/issues/7761
This commit is contained in:
Krish Dholakia 2025-01-18 08:07:39 -08:00 • committed by GitHub
parent 2fdbcca9ae
commit 5d065c2c35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 26 additions and 19 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -42,6 +42,8 @@ interface AdminPanelProps {
showSSOBanner: boolean;
premiumUser: boolean;
}
import { useBaseUrl } from "./constants";
import {
userUpdateUserCall,
@ -94,18 +96,11 @@ const AdminPanel: React.FC<AdminPanelProps> = ({
if (isLocal != true) {
console.log = function() {};
}
const [baseUrl, setBaseUrl] = useState(
isLocal ? "http://localhost:4000" : ""
);
const baseUrl = useBaseUrl();
const all_ip_address_allowed = "All IP Addresses Allowed";
let nonSssoUrl;
try {
nonSssoUrl = window.location.origin;
} catch (error) {
nonSssoUrl = "<your-proxy-url>";
}
let nonSssoUrl = baseUrl;
nonSssoUrl += "/fallback/login";
const handleShowAllowedIPs = async () => {
@ -202,13 +197,13 @@ const AdminPanel: React.FC<AdminPanelProps> = ({
const roles = ["proxy_admin", "proxy_admin_viewer"];
useEffect(() => {
if (router) {
const { protocol, host } = window.location;
const baseUrl = `${protocol}//${host}`;
setBaseUrl(baseUrl);
}
}, [router]);
// useEffect(() => {
// if (router) {
// const { protocol, host } = window.location;
// const baseUrl = `${protocol}//${host}`;
// setBaseUrl(baseUrl);
// }
// }, [router]);
useEffect(() => {
// Fetch model info and set the default selected model

View file

@ -0,0 +1,15 @@
// useBaseUrl.ts
import { useState, useEffect } from 'react';
export const useBaseUrl = () => {
const [baseUrl, setBaseUrl] = useState("http://localhost:4000");
useEffect(() => {
if (typeof window !== 'undefined') {
const { protocol, host } = window.location;
setBaseUrl(`${protocol}//${host}`);
}
}, []); // Removed router dependency
return baseUrl;
};