SEA User.auth(pair for @mmalmi

This commit is contained in:
Mark Nadal 2018-10-01 15:51:15 -07:00
parent 5b442293a8
commit 41482d25cc
4 changed files with 29 additions and 16 deletions

View File

@ -9,13 +9,13 @@
</div>
<p id="debug" style="position: fixed; bottom: 0px; color: white; height: 1em;"></p>
<script src="../jquery.js"></script>
<script src="/gun.js"></script>
<script src="/gun/nts.js"></script>
<script src="/gun/lib/webrtc.js"></script>
<script src="../../../gun/gun.js"></script>
<script src="../../../gun/nts.js"></script>
<script src="../../../gun/lib/webrtc.js"></script>
<script>
// Thanks to https://github.com/dmcinnes/HTML5-Asteroids
//var gun = Gun();
var gun = Gun(location.origin+'/gun');
var gun = Gun(location.host? location.origin+'/gun' : 'http://localhost:8765/gun');
var game = {gun: gun.get('example/game/space'), area: {}, ships: {}};
game.keys = {38: 'up', 37: 'left', 39: 'right', 40: 'down', 32: 'space'};
$(document).on('keydown', function(e){

4
gun.js
View File

@ -883,7 +883,7 @@
Gun.log.once("welcome", "Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!");
;"Please do not remove these messages unless you are paying for a monthly sponsorship, thanks!";
if(typeof window !== "undefined"){ (window.Gun = Gun).window = window }
if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window }
try{ if(typeof common !== "undefined"){ common.exports = Gun } }catch(e){}
module.exports = Gun;
@ -1290,7 +1290,7 @@
var cat = gun._, tmp;
if(tmp = cat.soul){ return cb(tmp, as, cat), gun }
if(tmp = cat.link){ return cb(tmp, as, cat), gun }
gun.get(function(msg, ev){
gun.get(function(msg, ev){ // TODO: Bug! Needs once semantics?
ev.rid(msg);
var at = ((at = msg.$) && at._) || {};
tmp = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put);

View File

@ -1,6 +1,6 @@
{
"name": "gun",
"version": "0.9.99995",
"version": "0.9.99996",
"description": "A realtime, decentralized, offline-first, graph data synchronization engine.",
"main": "index.js",
"browser": "gun.min.js",

31
sea.js
View File

@ -655,7 +655,7 @@
// Cheers! Tell me what you think.
var Gun = (SEA.window||{}).Gun || USE('./gun', 1);
Gun.SEA = SEA;
SEA.Gun = Gun;
SEA.GUN = SEA.Gun = Gun;
module.exports = SEA
})(USE, './sea');
@ -748,7 +748,7 @@
err = null
if(SEA.window){
var tmp = SEA.window.sessionStorage;
if(tmp && gunRoot._.opt.remember){
if(tmp && gunRoot._.opt.remember){ // TODO: Bug! This needs to be moved to finalize?
SEA.window.sessionStorage.alias = alias;
SEA.window.sessionStorage.tmp = pass;
}
@ -1213,6 +1213,26 @@
}
cat.ing = true;
const putErr = (msg) => (e) => {
const { message, err = message || '' } = e
Gun.log(msg)
var error = { err: msg+' Reason: '+err }
return cat.ing = false, gun.leave(), cb(error), gun;
}
var key = (alias.pub || alias.epub)? alias : (pass.pub || pass.epub)? pass : null;
if(key){
(async function(){ try {
alias = (typeof alias === 'string')? alias : null;
const login = finalizeLogin(alias, key, gunRoot, { pin: pin })
login.catch(putErr('Finalizing login failed!'))
return cat.ing = false, cb(await login), gun;
} catch(e){
return cat.ing = false, gun.leave(), cb(e), gun;
}}())
return gun;
}
if (!pass && pin) { (async function(){
try {
var r = await authRecall(gunRoot, { alias: alias, pin: pin })
@ -1224,13 +1244,6 @@
return gun;
}
const putErr = (msg) => (e) => {
const { message, err = message || '' } = e
Gun.log(msg)
var error = { err: msg+' Reason: '+err }
return cat.ing = false, gun.leave(), cb(error), gun;
}
(async function(){ try {
const keys = await authenticate(alias, pass, gunRoot)
if (!keys) {