Created
September 17, 2020 21:26
-
-
Save diatche/7969f828d9dfb807485cd7f29a5dd612 to your computer and use it in GitHub Desktop.
Revisions
-
diatche created this gist
Sep 17, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ <script src="https://cdn.jsdelivr.net/gh/amark/gun@master/gun.js"></script> <script src="https://cdn.jsdelivr.net/gh/amark/gun@master/sea.js"></script> <!-- <script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script> <script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script> --> <script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script> <script> ;(() => { // Reset by uncommenting the next line, run once and comment out again. // sessionStorage.clear(); localStorage.clear(); let gun = new Gun(); let user = gun.user(); let pub = ''; gun.on('auth', function (...args) { pub = user.is.pub; console.log('user is: ' + user.is.pub); this.to.next(...args); }); // Recall is sync, as it uses session storage. user.recall({ sessionStorage: true }, ack => { // But, this seems to be only called when there IS a recall console.log('recall ack: ' + JSON.stringify(_.pick(ack, ['ok', 'err', 'sea']), null, 2)); }); if (!pub) { console.log('no recall'); let runID = 'test-' + new Date().toISOString(); user.create(runID, '123', ack => { console.log('create user ack: ' + JSON.stringify(ack, null, 2)); // One does not simply recall without calling auth() :) user.auth(runID, '123', ack => { console.log('auth user ack: ' + JSON.stringify(_.pick(ack, ['ok', 'err', 'sea']), null, 2)); }); }); } })(); </script>