Created
July 19, 2019 15:26
-
-
Save bitnom/2b1d23e4ed3b7a00262edb6b5411befd to your computer and use it in GitHub Desktop.
Gun User Recall
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
user.recall(6 * 60, { // minutes | |
session: true, | |
hook: function(props) { // { iat, exp, remember } | |
console.log("got to hook") | |
var passed = (Time.now() / 1000) - props.iat; // seconds internally | |
return (passed < exp) ? ((props.exp += passed) && props) : props; | |
} | |
}).then(function(ack) { | |
console.log("got to then") | |
if (ack && ack.sea) { | |
$('#sign').hide(); | |
user.get('said').map().once(UI); | |
user.get('alias').val(function(name){ | |
//console.log(name) | |
let peers = gun.get('peers') | |
peers.once(function(data){ | |
if(data){ | |
setu(peers, {name: name}) | |
}else{ | |
peers.set({name: name}) | |
} | |
}) | |
}) | |
} else if (ack && ack.err && ack.err.toLowerCase().indexOf('missing pin') !== -1) { | |
// TODO: show UX for entering username & PIN for user.auth(username, undefined, { pin }) call! | |
} | |
}).catch(function(e) { | |
console.log("reauth error") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment