From ac7b00662ff261d1a06666a2d89747432d9b74a5 Mon Sep 17 00:00:00 2001 From: PhilReact Date: Mon, 16 Dec 2024 16:18:25 +0200 Subject: [PATCH] fix local node auth --- src/ExtStates/NotAuthenticated.tsx | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/ExtStates/NotAuthenticated.tsx b/src/ExtStates/NotAuthenticated.tsx index 548ef0b..a386186 100644 --- a/src/ExtStates/NotAuthenticated.tsx +++ b/src/ExtStates/NotAuthenticated.tsx @@ -82,8 +82,14 @@ export const NotAuthenticated = ({ const data = await response.json(); if (data?.height) { setHasLocalNode(true); + return true } - } catch (error) {} + return false + + } catch (error) { + return false + + } }, []); useEffect(() => { @@ -122,8 +128,9 @@ export const NotAuthenticated = ({ const validateApiKey = useCallback(async (key, fromStartUp) => { try { if (!currentNodeRef.current) return; + const stillHasLocal = await checkIfUserHasLocalNode() const isLocalKey = cleanUrl(key?.url) === "127.0.0.1:12391"; - if (isLocalKey && !hasLocalNodeRef.current && !fromStartUp) { + if (isLocalKey && !stillHasLocal && !fromStartUp) { throw new Error("Please turn on your local node"); } const isCurrentNodeLocal = @@ -185,6 +192,26 @@ export const NotAuthenticated = ({ } catch (error) { setIsValidApiKey(false); setUseLocalNode(false); + if(fromStartUp){ + setCurrentNode({ + url: "http://127.0.0.1:12391", + }); + window + .sendMessage("setApiKey", null) + .then((response) => { + if (response) { + setApiKey(null); + handleSetGlobalApikey(null); + } + }) + .catch((error) => { + console.error( + "Failed to set API key:", + error.message || "An error occurred" + ); + }); + return + } setInfoSnack({ type: "error", message: error?.message || "Select a valid apikey",