Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use keytar (for electron)

So it seems that electron has this module called keytar, but the documentation is lacking a lot, and I have no idea how to use it.

https://github.com/atom/node-keytar

My code right now is (in the main process)

const keytar = require('keytar');
...
keytar.setPassword('KeytarTest', 'AccountName', 'secret');
const secret = keytar.getPassword('KeytarTest', 'AccountName');
console.log(secret);

Which prints out

Promise { <pending> }

Could someone teach me how to get the actual password?

like image 295
ykonda Avatar asked May 27 '18 17:05

ykonda


1 Answers

Ok so after looking around, I found out the answer. You call the resulting promise and operate on the argument to the promise.

keytar.setPassword('KeytarTest', 'AccountName', 'secret');
const secret = keytar.getPassword('KeytarTest', 'AccountName');
secret.then((result) => {
    console.log("result: "+ result); // result will be 'secret'
});
like image 183
ykonda Avatar answered Nov 20 '22 09:11

ykonda