diff --git a/public/electron.js b/public/electron.js index eb8b772..81d56b9 100644 --- a/public/electron.js +++ b/public/electron.js @@ -141,3 +141,37 @@ ipcMain.handle( }); } ); + +ipcMain.handle("store-params", async (event, { key, params }) => { + return new Promise((resolve, reject) => { + const encryptedParams = safestorage.encryptString(JSON.stringify(params)); + storage.set(key, { data: encryptedParams }, (error) => { + if (error) { + reject(error); + } else { + resolve(); + } + }); + }); +}); + +ipcMain.handle("retrieve-params", async (event, { key }) => { + return new Promise((resolve, reject) => { + storage.get(key, (error, data) => { + if (error) { + reject(error); + } else { + if (data && data.data) { + try { + const decryptedParams = safestorage.decryptString(data.data); + resolve(JSON.parse(decryptedParams)); + } catch (decryptionError) { + reject(decryptionError); + } + } else { + resolve(null); + } + } + }); + }); +}); diff --git a/public/preload.js b/public/preload.js index 101c6e8..0383bb9 100644 --- a/public/preload.js +++ b/public/preload.js @@ -45,4 +45,21 @@ contextBridge.exposeInMainWorld("api", { throw error; } }, + storeParams: async (key, params) => { + try { + await ipcRenderer.invoke("store-params", { key, params }); + } catch (error) { + console.error("Storage error:", error); + throw error; + } + }, + retrieveParams: async (key) => { + try { + const params = await ipcRenderer.invoke("retrieve-params", { key }); + return params; + } catch (error) { + console.error("Retrieval error:", error); + throw error; + } + }, }); diff --git a/src/Components/Login.js b/src/Components/Login.js index 624a0c7..6acdcd8 100644 --- a/src/Components/Login.js +++ b/src/Components/Login.js @@ -84,6 +84,7 @@ function Login({ onClose, open }) { ); console.log("OTP Verification Response:", response); setResponseMessage(`OTP Verified: ${response.message}`); + await window.api.storeParams("serverResponse", response); handleClose(); } catch (error) { console.error("OTP Verification Error:", error); @@ -111,6 +112,18 @@ function Login({ onClose, open }) { } }; + // useEffect(() => { + // const fetchParams = async () => { + // try { + // const storedParams = await window.api.retrieveParams("serverResponse"); + // console.log("Stored Params:", storedParams); + // } catch (error) { + // console.error("Retrieval Error:", error); + // } + // }; + // fetchParams(); + // }, []); + return ( diff --git a/src/Components/Signup.js b/src/Components/Signup.js index 167fe7d..6a1c32d 100644 --- a/src/Components/Signup.js +++ b/src/Components/Signup.js @@ -128,6 +128,7 @@ function Signup({ onClose, open }) { console.log("OTP Verification Response:", response); console.log("otp:", otp); setResponseMessage(`OTP Verified: ${response.message}`); + await window.api.storeParams("serverResponse", response); handleClose(); } catch (error) { console.error("OTP Verification Error:", error); @@ -156,6 +157,18 @@ function Signup({ onClose, open }) { } }; + // useEffect(() => { + // const fetchParams = async () => { + // try { + // const storedParams = await window.api.retrieveParams("serverResponse"); + // console.log("Stored Params:", storedParams); + // } catch (error) { + // console.error("Retrieval Error:", error); + // } + // }; + // fetchParams(); + // }, []); + return (