Merge pull request #1746 from BerriAI/litellm_ui_stop_requiring_proxyBaseUrl

[Feat-UI] Quick spin Up -  remove proxyBaseUrl
This commit is contained in:
Ishaan Jaff 2024-02-01 13:10:04 -08:00 committed by GitHub
commit 42efa2a608
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 58 additions and 122 deletions

View file

@ -28,8 +28,6 @@ Allow your users to create, view their own keys through a UI
**Required .env variables on your Proxy**
```shell
PROXY_BASE_URL="<your deployed proxy endpoint>" example PROXY_BASE_URL=https://litellm-production-7002.up.railway.app/
# for Google SSO Login
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
@ -50,8 +48,6 @@ GOOGLE_CLIENT_SECRET=
**Required .env variables on your Proxy**
```shell
PROXY_BASE_URL="<your deployed proxy endpoint>" example PROXY_BASE_URL=https://litellm-production-7002.up.railway.app/
MICROSOFT_CLIENT_ID="84583a4d-"
MICROSOFT_CLIENT_SECRET="nbk8Q~"
MICROSOFT_TENANT="5a39737
@ -68,8 +64,6 @@ MICROSOFT_TENANT="5a39737
Set the following in your .env on the Proxy
```shell
PROXY_BASE_URL="<your deployed proxy endpoint>" example PROXY_BASE_URL=https://litellm-production-7002.up.railway.app/
UI_USERNAME=ishaan-litellm
UI_PASSWORD=langchain
```

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

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

@ -1,8 +1,8 @@
2:"$Sreact.suspense"
3:I[5250,["291","static/chunks/291-b42f47441ebb3671.js","931","static/chunks/app/page-390e012b130397f7.js"],""]
4:I[7476,["291","static/chunks/291-b42f47441ebb3671.js","931","static/chunks/app/page-390e012b130397f7.js"],""]
3:I[5250,["448","static/chunks/448-cd38799829cf7b57.js","931","static/chunks/app/page-cf0440186224a114.js"],""]
4:I[3239,["448","static/chunks/448-cd38799829cf7b57.js","931","static/chunks/app/page-cf0440186224a114.js"],""]
5:I[5613,[],""]
6:I[1778,[],""]
0:["8YrDFJdukjBa2XHc3AeKh",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},["$L1",["$","$2",null,{"fallback":["$","div",null,{"children":"Loading..."}],"children":["$","div",null,{"className":"flex min-h-screen flex-col items-center","children":[["$","nav",null,{"className":"left-0 right-0 top-0 flex justify-between items-center h-12","children":[["$","div",null,{"className":"text-left mx-4 my-2 absolute top-0 left-0","children":["$","div",null,{"className":"flex flex-col items-center","children":["$","$L3",null,{"href":"/","children":["$","button",null,{"className":"text-gray-800 text-2xl px-4 py-1 rounded text-center","children":"🚅 LiteLLM"}]}]}]}],["$","div",null,{"className":"text-right mx-4 my-2 absolute top-0 right-0","children":[["$","a",null,{"href":"https://docs.litellm.ai/docs/","target":"_blank","rel":"noopener noreferrer","children":["$","button",null,{"className":"border border-gray-800 rounded-lg text-gray-800 text-xl px-4 py-1 rounded p-1 mr-2 text-center","children":"Docs"}]}],["$","a",null,{"href":"https://calendly.com/d/4mp-gd3-k5k/berriai-1-1-onboarding-litellm-hosted-version","target":"_blank","rel":"noopener noreferrer","children":["$","button",null,{"className":"border border-gray-800 rounded-lg text-gray-800 text-xl px-4 py-1 rounded p-1 text-center","children":"Schedule Demo"}]}]]}]]}],["$","$L4",null,{}]]}]}],null]]},[null,["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_c23dc8","children":["$","$L5",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","loadingScripts":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L6",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"styles":null}]}]}],null]],[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/7384ba6288e79f81.css","precedence":"next","crossOrigin":""}]],"$L7"]]]]
0:["9KvKBLd4AqpwRy9Epc-98",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},["$L1",["$","$2",null,{"fallback":["$","div",null,{"children":"Loading..."}],"children":["$","div",null,{"className":"flex min-h-screen flex-col items-center","children":[["$","nav",null,{"className":"left-0 right-0 top-0 flex justify-between items-center h-12","children":[["$","div",null,{"className":"text-left mx-4 my-2 absolute top-0 left-0","children":["$","div",null,{"className":"flex flex-col items-center","children":["$","$L3",null,{"href":"/","children":["$","button",null,{"className":"text-gray-800 text-2xl px-4 py-1 rounded text-center","children":"🚅 LiteLLM"}]}]}]}],["$","div",null,{"className":"text-right mx-4 my-2 absolute top-0 right-0","children":[["$","a",null,{"href":"https://docs.litellm.ai/docs/","target":"_blank","rel":"noopener noreferrer","children":["$","button",null,{"className":"border border-gray-800 rounded-lg text-gray-800 text-xl px-4 py-1 rounded p-1 mr-2 text-center","children":"Docs"}]}],["$","a",null,{"href":"https://calendly.com/d/4mp-gd3-k5k/berriai-1-1-onboarding-litellm-hosted-version","target":"_blank","rel":"noopener noreferrer","children":["$","button",null,{"className":"border border-gray-800 rounded-lg text-gray-800 text-xl px-4 py-1 rounded p-1 text-center","children":"Schedule Demo"}]}]]}]]}],["$","$L4",null,{}]]}]}],null]]},[null,["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_c23dc8","children":["$","$L5",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","loadingScripts":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L6",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"styles":null}]}]}],null]],[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/7384ba6288e79f81.css","precedence":"next","crossOrigin":""}]],"$L7"]]]]
7:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"Create Next App"}],["$","meta","3",{"name":"description","content":"Generated by create next app"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]]
1:null

View file

@ -115,12 +115,8 @@ import json
import logging
from typing import Union
proxy_base_url = os.getenv("PROXY_BASE_URL", None)
ui_link = f"/ui/?proxyBaseUrl={proxy_base_url}"
ui_link = f"/ui/"
ui_message = f"👉 [LiteLLM Admin Panel on /ui]({ui_link}). Create, Edit Keys with SSO"
if proxy_base_url is None:
ui_message = "👉 LiteLLM Admin Panel - 'PROXY_BASE_URL' not set in env, see [UI docs](https://docs.litellm.ai/docs/proxy/ui)"
app = FastAPI(
docs_url="/",
title="LiteLLM API",
@ -2960,17 +2956,11 @@ async def google_login(request: Request):
"""
microsoft_client_id = os.getenv("MICROSOFT_CLIENT_ID", None)
google_client_id = os.getenv("GOOGLE_CLIENT_ID", None)
redirect_url = os.getenv("PROXY_BASE_URL", None)
# get url from request
redirect_url = str(request.base_url)
ui_username = os.getenv("UI_USERNAME")
if redirect_url is None:
raise ProxyException(
message="PROXY_BASE_URL not set. Set it in .env file",
type="auth_error",
param="PROXY_BASE_URL",
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
if redirect_url.endswith("/"):
redirect_url += "sso/callback"
else:
@ -3069,14 +3059,7 @@ async def login(request: Request):
if litellm_ui_link_in_env is not None:
litellm_dashboard_ui = litellm_ui_link_in_env
litellm_dashboard_ui += (
"?userID="
+ user_id
+ "&accessToken="
+ key
+ "&proxyBaseUrl="
+ os.getenv("PROXY_BASE_URL")
)
litellm_dashboard_ui += "?userID=" + user_id + "&accessToken=" + key
return RedirectResponse(url=litellm_dashboard_ui)
else:
raise ProxyException(
@ -3094,14 +3077,9 @@ async def auth_callback(request: Request):
microsoft_client_id = os.getenv("MICROSOFT_CLIENT_ID", None)
google_client_id = os.getenv("GOOGLE_CLIENT_ID", None)
redirect_url = os.getenv("PROXY_BASE_URL", None)
if redirect_url is None:
raise ProxyException(
message="PROXY_BASE_URL not set. Set it in .env file",
type="auth_error",
param="PROXY_BASE_URL",
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
# get url from request
redirect_url = str(request.base_url)
if redirect_url.endswith("/"):
redirect_url += "sso/callback"
else:
@ -3166,31 +3144,14 @@ async def auth_callback(request: Request):
key = response["token"] # type: ignore
user_id = response["user_id"] # type: ignore
# get current host:port/ui
proxy_base_url = os.getenv("PROXY_BASE_URL", None)
if proxy_base_url is None:
raise ProxyException(
message="PROXY_BASE_URL not set. Set it in .env file",
type="auth_error",
param="PROXY_BASE_URL",
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
litellm_dashboard_ui = proxy_base_url
if proxy_base_url.endswith("/"):
litellm_dashboard_ui += "ui/"
proxy_base_url = proxy_base_url[:-1]
else:
litellm_dashboard_ui += "/ui/"
litellm_dashboard_ui = "/ui/"
import jwt
jwt_token = jwt.encode(
{"user_id": user_id, "key": key}, "secret", algorithm="HS256"
)
litellm_dashboard_ui += (
"?userID=" + user_id + "&token=" + jwt_token + "&proxyBaseUrl=" + proxy_base_url
)
litellm_dashboard_ui += "?userID=" + user_id + "&token=" + jwt_token
# if a user has logged in they should be allowed to create keys - this ensures that it's set to True
general_settings["allow_user_auth"] = True

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

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

@ -1,8 +1,8 @@
2:"$Sreact.suspense"
3:I[5250,["291","static/chunks/291-b42f47441ebb3671.js","931","static/chunks/app/page-390e012b130397f7.js"],""]
4:I[7476,["291","static/chunks/291-b42f47441ebb3671.js","931","static/chunks/app/page-390e012b130397f7.js"],""]
3:I[5250,["448","static/chunks/448-cd38799829cf7b57.js","931","static/chunks/app/page-cf0440186224a114.js"],""]
4:I[3239,["448","static/chunks/448-cd38799829cf7b57.js","931","static/chunks/app/page-cf0440186224a114.js"],""]
5:I[5613,[],""]
6:I[1778,[],""]
0:["8YrDFJdukjBa2XHc3AeKh",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},["$L1",["$","$2",null,{"fallback":["$","div",null,{"children":"Loading..."}],"children":["$","div",null,{"className":"flex min-h-screen flex-col items-center","children":[["$","nav",null,{"className":"left-0 right-0 top-0 flex justify-between items-center h-12","children":[["$","div",null,{"className":"text-left mx-4 my-2 absolute top-0 left-0","children":["$","div",null,{"className":"flex flex-col items-center","children":["$","$L3",null,{"href":"/","children":["$","button",null,{"className":"text-gray-800 text-2xl px-4 py-1 rounded text-center","children":"🚅 LiteLLM"}]}]}]}],["$","div",null,{"className":"text-right mx-4 my-2 absolute top-0 right-0","children":[["$","a",null,{"href":"https://docs.litellm.ai/docs/","target":"_blank","rel":"noopener noreferrer","children":["$","button",null,{"className":"border border-gray-800 rounded-lg text-gray-800 text-xl px-4 py-1 rounded p-1 mr-2 text-center","children":"Docs"}]}],["$","a",null,{"href":"https://calendly.com/d/4mp-gd3-k5k/berriai-1-1-onboarding-litellm-hosted-version","target":"_blank","rel":"noopener noreferrer","children":["$","button",null,{"className":"border border-gray-800 rounded-lg text-gray-800 text-xl px-4 py-1 rounded p-1 text-center","children":"Schedule Demo"}]}]]}]]}],["$","$L4",null,{}]]}]}],null]]},[null,["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_c23dc8","children":["$","$L5",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","loadingScripts":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L6",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"styles":null}]}]}],null]],[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/7384ba6288e79f81.css","precedence":"next","crossOrigin":""}]],"$L7"]]]]
0:["9KvKBLd4AqpwRy9Epc-98",[[["",{"children":["__PAGE__",{}]},"$undefined","$undefined",true],["",{"children":["__PAGE__",{},["$L1",["$","$2",null,{"fallback":["$","div",null,{"children":"Loading..."}],"children":["$","div",null,{"className":"flex min-h-screen flex-col items-center","children":[["$","nav",null,{"className":"left-0 right-0 top-0 flex justify-between items-center h-12","children":[["$","div",null,{"className":"text-left mx-4 my-2 absolute top-0 left-0","children":["$","div",null,{"className":"flex flex-col items-center","children":["$","$L3",null,{"href":"/","children":["$","button",null,{"className":"text-gray-800 text-2xl px-4 py-1 rounded text-center","children":"🚅 LiteLLM"}]}]}]}],["$","div",null,{"className":"text-right mx-4 my-2 absolute top-0 right-0","children":[["$","a",null,{"href":"https://docs.litellm.ai/docs/","target":"_blank","rel":"noopener noreferrer","children":["$","button",null,{"className":"border border-gray-800 rounded-lg text-gray-800 text-xl px-4 py-1 rounded p-1 mr-2 text-center","children":"Docs"}]}],["$","a",null,{"href":"https://calendly.com/d/4mp-gd3-k5k/berriai-1-1-onboarding-litellm-hosted-version","target":"_blank","rel":"noopener noreferrer","children":["$","button",null,{"className":"border border-gray-800 rounded-lg text-gray-800 text-xl px-4 py-1 rounded p-1 text-center","children":"Schedule Demo"}]}]]}]]}],["$","$L4",null,{}]]}]}],null]]},[null,["$","html",null,{"lang":"en","children":["$","body",null,{"className":"__className_c23dc8","children":["$","$L5",null,{"parallelRouterKey":"children","segmentPath":["children"],"loading":"$undefined","loadingStyles":"$undefined","loadingScripts":"$undefined","hasLoading":false,"error":"$undefined","errorStyles":"$undefined","errorScripts":"$undefined","template":["$","$L6",null,{}],"templateStyles":"$undefined","templateScripts":"$undefined","notFound":[["$","title",null,{"children":"404: This page could not be found."}],["$","div",null,{"style":{"fontFamily":"system-ui,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\"","height":"100vh","textAlign":"center","display":"flex","flexDirection":"column","alignItems":"center","justifyContent":"center"},"children":["$","div",null,{"children":[["$","style",null,{"dangerouslySetInnerHTML":{"__html":"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}"}}],["$","h1",null,{"className":"next-error-h1","style":{"display":"inline-block","margin":"0 20px 0 0","padding":"0 23px 0 0","fontSize":24,"fontWeight":500,"verticalAlign":"top","lineHeight":"49px"},"children":"404"}],["$","div",null,{"style":{"display":"inline-block"},"children":["$","h2",null,{"style":{"fontSize":14,"fontWeight":400,"lineHeight":"49px","margin":0},"children":"This page could not be found."}]}]]}]}]],"notFoundStyles":[],"styles":null}]}]}],null]],[[["$","link","0",{"rel":"stylesheet","href":"/ui/_next/static/css/7384ba6288e79f81.css","precedence":"next","crossOrigin":""}]],"$L7"]]]]
7:[["$","meta","0",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","1",{"charSet":"utf-8"}],["$","title","2",{"children":"Create Next App"}],["$","meta","3",{"name":"description","content":"Generated by create next app"}],["$","link","4",{"rel":"icon","href":"/ui/favicon.ico","type":"image/x-icon","sizes":"16x16"}],["$","meta","5",{"name":"next-size-adjust"}]]
1:null

View file

@ -12,7 +12,6 @@ const { Option } = Select;
interface CreateKeyProps {
userID: string;
accessToken: string;
proxyBaseUrl: string;
data: any[] | null;
setData: React.Dispatch<React.SetStateAction<any[] | null>>;
}
@ -20,7 +19,6 @@ interface CreateKeyProps {
const CreateKey: React.FC<CreateKeyProps> = ({
userID,
accessToken,
proxyBaseUrl,
data,
setData,
}) => {
@ -51,7 +49,7 @@ const CreateKey: React.FC<CreateKeyProps> = ({
formValues.models = [];
}
setIsModalVisible(true);
const response = await keyCreateCall(proxyBaseUrl, accessToken, userID, formValues);
const response = await keyCreateCall(accessToken, userID, formValues);
setData((prevData) => (prevData ? [...prevData, response] : [response])); // Check if prevData is null
setApiKey(response["key"]);
message.success("API Key Created");

View file

@ -4,7 +4,6 @@
import { message } from 'antd';
export const keyCreateCall = async (
proxyBaseUrl: string,
accessToken: string,
userID: string,
formValues: Record<string, any> // Assuming formValues is an object
@ -22,7 +21,7 @@ export const keyCreateCall = async (
}
}
const response = await fetch(`${proxyBaseUrl}/key/generate`, {
const response = await fetch(`/key/generate`, {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
@ -53,12 +52,11 @@ export const keyCreateCall = async (
export const keyDeleteCall = async (
proxyBaseUrl: String,
accessToken: String,
user_key: String
) => {
try {
const response = await fetch(`${proxyBaseUrl}/key/delete`, {
const response = await fetch(`/key/delete`, {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
@ -84,13 +82,12 @@ export const keyDeleteCall = async (
};
export const userInfoCall = async (
proxyBaseUrl: String,
accessToken: String,
userID: String
) => {
try {
const response = await fetch(
`${proxyBaseUrl}/user/info?user_id=${userID}`,
`/user/info?user_id=${userID}`,
{
method: "GET",
headers: {

View file

@ -14,8 +14,6 @@ const UserDashboard = () => {
const searchParams = useSearchParams();
const userID = searchParams.get("userID");
const proxyBaseUrl = searchParams.get("proxyBaseUrl");
const token = searchParams.get("token");
const [accessToken, setAccessToken] = useState<string | null>(null);
@ -34,11 +32,10 @@ const UserDashboard = () => {
}
}
if (userID && accessToken && proxyBaseUrl && !data) {
if (userID && accessToken && !data) {
const fetchData = async () => {
try {
const response = await userInfoCall(
proxyBaseUrl,
accessToken,
userID
);
@ -50,20 +47,13 @@ const UserDashboard = () => {
};
fetchData();
}
}, [userID, token, accessToken, proxyBaseUrl, data]);
}, [userID, token, accessToken, data]);
if (userID == null || token == null) {
if (proxyBaseUrl == null) {
return (
<div>
<EnterProxyUrl />
</div>
);
}
else if (userID == null || token == null) {
const baseUrl = proxyBaseUrl.endsWith('/') ? proxyBaseUrl : proxyBaseUrl + '/';
// Now you can construct the full URL
const url = `${baseUrl}sso/key/generate`;
const url = `/sso/key/generate`;
window.location.href = url;
@ -80,14 +70,12 @@ const UserDashboard = () => {
<ViewKeyTable
userID={userID}
accessToken={accessToken}
proxyBaseUrl={proxyBaseUrl}
data={data}
setData={setData}
/>
<CreateKey
userID={userID}
accessToken={accessToken}
proxyBaseUrl={proxyBaseUrl}
data={data}
setData={setData}
/>

View file

@ -20,7 +20,6 @@ import {
interface ViewKeyTableProps {
userID: string;
accessToken: string;
proxyBaseUrl: string;
data: any[] | null;
setData: React.Dispatch<React.SetStateAction<any[] | null>>;
}
@ -28,7 +27,6 @@ interface ViewKeyTableProps {
const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
userID,
accessToken,
proxyBaseUrl,
data,
setData,
}) => {
@ -37,7 +35,7 @@ const ViewKeyTable: React.FC<ViewKeyTableProps> = ({
return;
}
try {
await keyDeleteCall(proxyBaseUrl, accessToken, token);
await keyDeleteCall(accessToken, token);
// Successfully completed the deletion. Update the state to trigger a rerender.
const filteredData = data.filter((item) => item.token !== token);
setData(filteredData);