diff --git a/electron/package-lock.json b/electron/package-lock.json index c1b2723..b3b1a6b 100644 --- a/electron/package-lock.json +++ b/electron/package-lock.json @@ -20,7 +20,7 @@ }, "devDependencies": { "@electron/notarize": "^2.5.0", - "electron": "^26.2.2", + "electron": "^32.3.1", "electron-builder": "^25.1.8", "shelljs": "^0.8.5", "typescript": "^5.0.4" @@ -2624,14 +2624,14 @@ } }, "node_modules/electron": { - "version": "26.6.10", - "resolved": "https://registry.npmjs.org/electron/-/electron-26.6.10.tgz", - "integrity": "sha512-pV2SD0RXzAiNRb/2yZrsVmVkBOMrf+DVsPulIgRjlL0+My9BL5spFuhHVMQO9yHl9tFpWtuRpQv0ofM/i9P8xg==", + "version": "32.3.1", + "resolved": "https://registry.npmjs.org/electron/-/electron-32.3.1.tgz", + "integrity": "sha512-gjHN9NagNajvllKrTZVwGuCqX1hPF7OI6hkCDFRCbqT5Zr05d17qjDhjyTNBmTca2DpvZIYQMRbqieNCcglVYQ==", "dev": true, "hasInstallScript": true, "dependencies": { "@electron/get": "^2.0.0", - "@types/node": "^18.11.18", + "@types/node": "^20.9.0", "extract-zip": "^2.0.1" }, "bin": { @@ -2909,18 +2909,18 @@ } }, "node_modules/electron/node_modules/@types/node": { - "version": "18.19.68", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.68.tgz", - "integrity": "sha512-QGtpFH1vB99ZmTa63K4/FU8twThj4fuVSBkGddTp7uIL/cuoLWIUSL2RcOaigBhfR+hg5pgGkBnkoOxrTVBMKw==", + "version": "20.17.19", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.19.tgz", + "integrity": "sha512-LEwC7o1ifqg/6r2gn9Dns0f1rhK+fPFDoMiceTJ6kWmVk6bgXBI/9IOWfVan4WiAavK9pIVWdX0/e3J+eEUh5A==", "dev": true, "dependencies": { - "undici-types": "~5.26.4" + "undici-types": "~6.19.2" } }, "node_modules/electron/node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", "dev": true }, "node_modules/elementtree": { diff --git a/electron/package.json b/electron/package.json index e2c4966..b520190 100644 --- a/electron/package.json +++ b/electron/package.json @@ -47,7 +47,7 @@ "electron-window-state": "^5.0.3" }, "devDependencies": { - "electron": "^26.2.2", + "electron": "^32.3.1", "electron-builder": "^25.1.8", "@electron/notarize": "^2.5.0", "typescript": "^5.0.4", diff --git a/src/ExtStates/NotAuthenticated.tsx b/src/ExtStates/NotAuthenticated.tsx index 6bfd456..a1aaf19 100644 --- a/src/ExtStates/NotAuthenticated.tsx +++ b/src/ExtStates/NotAuthenticated.tsx @@ -191,28 +191,45 @@ export const NotAuthenticated = ({ const validateApiKey = useCallback(async (key, fromStartUp) => { try { + if(key === "isGateway") return const isLocalKey = cleanUrl(key?.url) === "127.0.0.1:12391"; - if(fromStartUp && key?.url && key?.apikey && !isLocalKey && !gateways.some(gateway => apiKey?.url?.includes(gateway))){ + if (fromStartUp && key?.url && key?.apikey && !isLocalKey && !gateways.some(gateway => key?.url?.includes(gateway))) { setCurrentNode({ url: key?.url, apikey: key?.apikey, }); - const url = `${key?.url}/lists/testlist?apiKey=${key?.apikey}`; - const response = await fetch(url); - - // Assuming the response is in plain text and will be 'true' or 'false' - const data = await response.json(); - if (data && !data?.error) { - setIsValidApiKey(true); - setUseLocalNode(true); - return - } + let isValid = false + + const url = `${key?.url}/admin/settings/localAuthBypassEnabled`; + const response = await fetch(url); + + // Assuming the response is in plain text and will be 'true' or 'false' + const data = await response.text(); + if(data && data === 'true'){ + isValid = true + } else { + const url2 = `${key?.url}/admin/apikey/test?apiKey=${key?.apikey}`; + const response2 = await fetch(url2); + + // Assuming the response is in plain text and will be 'true' or 'false' + const data2 = await response2.text(); + if (data2 === "true") { + isValid = true + } + } + + if (isValid) { + setIsValidApiKey(true); + setUseLocalNode(true); + return + } + } if (!currentNodeRef.current) return; const stillHasLocal = await checkIfUserHasLocalNode() - + if (isLocalKey && !stillHasLocal && !fromStartUp) { throw new Error("Please turn on your local node"); } @@ -235,13 +252,29 @@ export const NotAuthenticated = ({ } else if (currentNodeRef.current) { payload = currentNodeRef.current; } - const url = `${payload?.url}/lists/testlist?apiKey=${payload?.apikey}`; + let isValid = false + + + const url = `${payload?.url}/admin/settings/localAuthBypassEnabled`; const response = await fetch(url); // Assuming the response is in plain text and will be 'true' or 'false' - const data = await response.json(); + const data = await response.text(); + if(data && data === 'true'){ + isValid = true + } else { + const url2 = `${payload?.url}/admin/apikey/test?apiKey=${payload?.apikey}`; + const response2 = await fetch(url2); + + // Assuming the response is in plain text and will be 'true' or 'false' + const data2 = await response2.text(); + if (data2 === "true") { + isValid = true + } + } + - if (data && !data?.error) { + if (isValid) { window .sendMessage("setApiKey", payload) .then((response) => { @@ -263,21 +296,24 @@ export const NotAuthenticated = ({ } else { setIsValidApiKey(false); setUseLocalNode(false); - setInfoSnack({ - type: "error", - message: "Select a valid apikey", - }); - setOpenSnack(true); + if(!fromStartUp){ + setInfoSnack({ + type: "error", + message: "Select a valid apikey", + }); + setOpenSnack(true); + } + } } catch (error) { setIsValidApiKey(false); setUseLocalNode(false); - if(fromStartUp){ + if (fromStartUp) { setCurrentNode({ url: "http://127.0.0.1:12391", }); window - .sendMessage("setApiKey", null) + .sendMessage("setApiKey", "isGateway") .then((response) => { if (response) { setApiKey(null); @@ -292,11 +328,13 @@ export const NotAuthenticated = ({ }); return } + if(!fromStartUp){ setInfoSnack({ type: "error", message: error?.message || "Select a valid apikey", }); setOpenSnack(true); + } console.error("Error validating API key:", error); } }, []); @@ -318,7 +356,7 @@ export const NotAuthenticated = ({ url: removeTrailingSlash(url), apikey: customApikey, }); - } else if (url && customApikey) { + } else if (url) { nodes.push({ url: removeTrailingSlash(url), apikey: customApikey, @@ -326,9 +364,7 @@ export const NotAuthenticated = ({ } setCustomNodes(nodes); - if(window?.electronAPI?.setAllowedDomains){ - window.electronAPI.setAllowedDomains(nodes?.map((node)=> node.url)) - } + setCustomNodeToSaveIndex(null); if (!nodes) return; window @@ -338,6 +374,9 @@ export const NotAuthenticated = ({ setMode("list"); setUrl("http://"); setCustomApiKey(""); + if(window?.electronAPI?.setAllowedDomains){ + window.electronAPI.setAllowedDomains(nodes?.map((node) => node.url)) + } // add alert if needed } }) @@ -810,7 +849,7 @@ export const NotAuthenticated = ({