我正在尝试使用keytar.js保存密码,由于某些原因,在使用keytar中的任何函数时,我总是收到这个错误。
有关信息: lib。已经安装,并且函数已经存在(我使用console.log进行了检查),它们在catch()中工作得很好。
下面是一些代码:
const keytar = require("keytar");我在react的componentDidMount()函数中使用它,
我尝试了这两个版本,但它们似乎都不起作用:
keytar
.setPassword("stoma", "user", user)
.then(() => {
console.log("User .. OK !");
})
.catch(() => {
console.log("User .. ERROR !");
ok = false;
})和
keytar.setPassword("stoma", "statut", "true");下面是一些错误日志:
keytar.js:38 Uncaught (in promise) TypeError: keytar.setPassword is not a function
at keytar.js:38
at keytar.js:12
at new Promise (<anonymous>)
at callbackPromise (keytar.js:11)
at Object.setPassword (keytar.js:37)
at _callee$ (Login.js:52)
at tryCatch (runtime.js:62)
at Generator.invoke [as _invoke] (runtime.js:288)
at Generator.prototype.(:3000/anonymous function) [as next] (http://localhost:3000/static/js/0.chunk.js:1881:21)
at asyncGeneratorStep (asyncToGenerator.js:3)
at _next (asyncToGenerator.js:25)
at asyncToGenerator.js:32
at new Promise (<anonymous>)
at asyncToGenerator.js:21
at _validate (Login.js:48)
at validate (Login.js:48)如果有人能帮上忙,我会grateful.Thank你。
发布于 2021-03-03 19:46:17
当使用Electron时,您必须通过主进程使用keytar。从渲染进程调用keytar将不起作用。
在this question中解析时,您必须执行以下操作:
在main.js文件中,您必须使用所需的keytar逻辑定义要调用的侦听器。在这种情况下,获取和设置密码
ipcMain.on('get-password', (event, user) => {
event.returnValue = keytar.getPassword('ServiceName', user);
});
ipcMain.on('set-password', (event, user, pass) => {
event.returnValue = keytar.replacePassword('ServiceName', user, pass);
});然后,您可以从渲染器进程调用
const password = ipcRenderer.sendSync('get-password', user);或
ipcRenderer.sendSync('set-password', user, pass);https://stackoverflow.com/questions/56565138
复制相似问题