From 8dcbeb5e3960dc0584168650eb82106782e74a7b Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Thu, 17 Aug 2023 19:51:28 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(base.py):=20set=20AUTO=5FLOG?= =?UTF-8?q?IN=20to=20False=20to=20disable=20automatic=20login=20as=20a=20s?= =?UTF-8?q?uper=20user=20=E2=9C=A8=20feat(App.tsx):=20add=20logout=20funct?= =?UTF-8?q?ion=20to=20useContext=20and=20handle=20page=20refresh=20to=20ma?= =?UTF-8?q?intain=20user=20login=20state=20=F0=9F=90=9B=20fix(SecretKeyMod?= =?UTF-8?q?al/index.tsx):=20add=20onCloseModal=20function=20to=20handle=20?= =?UTF-8?q?closing=20modal=20when=20API=20key=20is=20not=20available=20?= =?UTF-8?q?=E2=9C=A8=20feat(ApiKeysPage/index.tsx):=20add=20onCloseModal?= =?UTF-8?q?=20prop=20to=20SecretKeyModal=20component=20to=20refresh=20API?= =?UTF-8?q?=20keys=20after=20creating=20a=20new=20key=20=F0=9F=90=9B=20fix?= =?UTF-8?q?(ApiKeysPage/index.tsx):=20replace=20getIdKeyHidden=20function?= =?UTF-8?q?=20with=20directly=20accessing=20api=5Fkey=20property=20in=20Ap?= =?UTF-8?q?iKey=20object=20=E2=9C=A8=20feat(types/components/index.ts):=20?= =?UTF-8?q?add=20onCloseModal=20function=20to=20ApiKeyType=20type=20to=20h?= =?UTF-8?q?andle=20closing=20modals?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/services/settings/base.py | 2 +- src/frontend/src/App.tsx | 5 ++++- src/frontend/src/modals/SecretKeyModal/index.tsx | 10 +++++++--- src/frontend/src/pages/ApiKeysPage/index.tsx | 16 ++++++---------- src/frontend/src/types/components/index.ts | 10 ++++++++++ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/backend/langflow/services/settings/base.py b/src/backend/langflow/services/settings/base.py index 65a1a2909..2395c5f6c 100644 --- a/src/backend/langflow/services/settings/base.py +++ b/src/backend/langflow/services/settings/base.py @@ -55,7 +55,7 @@ class Settings(BaseSettings): # If AUTO_LOGIN = True # > The application does not request login and logs in automatically as a super user. - AUTO_LOGIN: bool = True + AUTO_LOGIN: bool = False FIRST_SUPERUSER: str = "langflow" FIRST_SUPERUSER_PASSWORD: str = "langflow" diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index a691472c2..a5bac422d 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -134,7 +134,7 @@ export default function App() { }; //this function is to get the user logged in when the page is refreshed - const { setUserData, getAuthentication, login, setAutoLogin } = + const { setUserData, getAuthentication, login, setAutoLogin, logout } = useContext(AuthContext); useEffect(() => { @@ -156,6 +156,9 @@ export default function App() { }) .catch((error) => {}); } + else{ + setLoading(false); + } }); }, 500); }, []); diff --git a/src/frontend/src/modals/SecretKeyModal/index.tsx b/src/frontend/src/modals/SecretKeyModal/index.tsx index 35b3ae139..393088407 100644 --- a/src/frontend/src/modals/SecretKeyModal/index.tsx +++ b/src/frontend/src/modals/SecretKeyModal/index.tsx @@ -21,6 +21,7 @@ export default function SecretKeyModal({ children, icon, data, + onCloseModal }: ApiKeyType) { const Icon: any = nodeIconsLucide[icon]; const [open, setOpen] = useState(false); @@ -31,7 +32,7 @@ export default function SecretKeyModal({ const [renderKey, setRenderKey] = useState(false); const [textCopied, setTextCopied] = useState(true); const { setSuccessData } = useContext(alertContext); - const inputRef = useRef(null); + const inputRef = useRef(null); function handleInput({ target: { name, value }, @@ -44,6 +45,9 @@ export default function SecretKeyModal({ setRenderKey(false); resetForm(); } + else{ + onCloseModal(); + } }, [open]); function resetForm() { @@ -54,8 +58,8 @@ export default function SecretKeyModal({ const handleCopyClick = async () => { if (apiKeyValue) { await navigator.clipboard.writeText(apiKeyValue); - inputRef.current.focus(); - inputRef.current.select(); + inputRef?.current?.focus(); + inputRef?.current?.select(); setSuccessData({ title: "API Key copied!", }); diff --git a/src/frontend/src/pages/ApiKeysPage/index.tsx b/src/frontend/src/pages/ApiKeysPage/index.tsx index 171e258e6..d91005191 100644 --- a/src/frontend/src/pages/ApiKeysPage/index.tsx +++ b/src/frontend/src/pages/ApiKeysPage/index.tsx @@ -17,6 +17,7 @@ import ConfirmationModal from "../../modals/ConfirmationModal"; import SecretKeyModal from "../../modals/SecretKeyModal"; import moment from "moment"; +import { ApiKey } from "../../types/components"; export default function ApiKeysPage() { const [loadingKeys, setLoadingKeys] = useState(true); @@ -35,7 +36,7 @@ export default function ApiKeysPage() { setLoadingKeys(true); if (userData) { getApiKey(userData.id) - .then((keys) => { + .then((keys: [ApiKey]) => { keysList.current = keys["api_keys"]; setUserId(keys["user_id"]); setLoadingKeys(false); @@ -77,12 +78,6 @@ export default function ApiKeysPage() { ); } - function getIdKeyHidden(apiKey: string) { - const firstTwoChars = apiKey.slice(0, 2); - const lastFourChars = apiKey.slice(-4); - return firstTwoChars + "..." + lastFourChars; - } - return ( <> {userData && ( @@ -153,7 +148,7 @@ export default function ApiKeysPage() { {!loadingKeys && ( - {keysList.current.map((api_keys, index) => ( + {keysList.current.map((api_keys: ApiKey, index: number) => ( @@ -164,11 +159,11 @@ export default function ApiKeysPage() { - {getIdKeyHidden(api_keys.id)} + {api_keys.api_key} - {moment(api_keys.create_at).format( + {moment(api_keys.created_at).format( "YYYY-MM-DD HH:mm" )} @@ -217,6 +212,7 @@ export default function ApiKeysPage() { confirmationText="Create secret key" icon={"Key"} data={userId} + onCloseModal={() => {getKeys()}} >