These are some helpful snippets for sending credentials between processes in a React and Electron setup. Note I am using electron-settings.
Last active
July 18, 2018 03:53
-
-
Save joshuawootonn/2462ee1a1985707a4fb5f91aae3eb933 to your computer and use it in GitHub Desktop.
Sending Credentials between processes in Electron/React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { ipcMain } = require('electron'); | |
const settings = require('electron-settings'); | |
/* | |
... | |
*/ | |
ipcMain.on(IPCConstants.SET_CRED, (event, arg) => { | |
settings.set(`${SETTINGS.USER_CRED}`, { | |
username: arg.username, | |
password: arg.password, | |
}); | |
event.returnValue = arg; | |
}); | |
ipcMain.on(IPCConstants.GET_CRED, event => { | |
const cred = { | |
username: settings.get(`${SETTINGS.USER_CRED}.username`), | |
password: settings.get(`${SETTINGS.USER_CRED}.password`), | |
}; | |
event.returnValue = cred; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setCred = (username,password) => { | |
ipcRenderer.sendSync(IPCConstants.SET_CRED, { username, password }); | |
} | |
getCred = () => { | |
return ipcRenderer.sendSync(IPCConstants.GET_CRED, ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment