fix local node auth

This commit is contained in:
PhilReact 2024-12-16 16:18:25 +02:00
parent f89771eaf4
commit ac7b00662f

View File

@ -82,8 +82,14 @@ export const NotAuthenticated = ({
const data = await response.json(); const data = await response.json();
if (data?.height) { if (data?.height) {
setHasLocalNode(true); setHasLocalNode(true);
return true
}
return false
} catch (error) {
return false
} }
} catch (error) {}
}, []); }, []);
useEffect(() => { useEffect(() => {
@ -122,8 +128,9 @@ export const NotAuthenticated = ({
const validateApiKey = useCallback(async (key, fromStartUp) => { const validateApiKey = useCallback(async (key, fromStartUp) => {
try { try {
if (!currentNodeRef.current) return; if (!currentNodeRef.current) return;
const stillHasLocal = await checkIfUserHasLocalNode()
const isLocalKey = cleanUrl(key?.url) === "127.0.0.1:12391"; 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"); throw new Error("Please turn on your local node");
} }
const isCurrentNodeLocal = const isCurrentNodeLocal =
@ -185,6 +192,26 @@ export const NotAuthenticated = ({
} catch (error) { } catch (error) {
setIsValidApiKey(false); setIsValidApiKey(false);
setUseLocalNode(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({ setInfoSnack({
type: "error", type: "error",
message: error?.message || "Select a valid apikey", message: error?.message || "Select a valid apikey",