Skip to content

Commit

Permalink
store creds
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa-Kris committed Jun 21, 2024
1 parent 10572f5 commit 4a3b18f
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
34 changes: 34 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
});
});
17 changes: 17 additions & 0 deletions public/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
},
});
13 changes: 13 additions & 0 deletions src/Components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
<Dialog sx={{ p: 4 }} onClose={handleClose} open={open}>
<Typography align="center" variant="h6" sx={{ pt: 3 }}>
Expand Down
13 changes: 13 additions & 0 deletions src/Components/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
<Dialog sx={{ p: 4 }} onClose={handleClose} open={open}>
<Typography align="center" variant="h6" sx={{ pt: 3 }}>
Expand Down

0 comments on commit 4a3b18f

Please sign in to comment.