diff --git a/lib/rs3.js b/lib/rs3.js index 38015ec5..3aefc4dd 100644 --- a/lib/rs3.js +++ b/lib/rs3.js @@ -94,7 +94,7 @@ function Store(opt){ // Stream interface requires a final call to know when to be done. cb.end = true; cb(); } - Gun.obj.map(cbs, cbe); + // Gun.obj.map(cbs, cbe); // lets see if fixes heroku if(!IT){ Gun.obj.del(c.l, 1); return } params.ContinuationToken = data.NextContinuationToken; store.list(cb, match, params, cbs); diff --git a/sea.js b/sea.js index 2319fef8..936d4e94 100644 --- a/sea.js +++ b/sea.js @@ -964,7 +964,7 @@ User.prototype.auth = function(...args){ // TODO: this PR with arguments need to be cleaned up / refactored. var pair = typeof args[0] === 'object' && (args[0].pub || args[0].epub) ? args[0] : typeof args[1] === 'object' && (args[1].pub || args[1].epub) ? args[1] : null; var alias = !pair && typeof args[0] === 'string' ? args[0] : null; - var pass = alias && typeof args[1] === 'string' ? args[1] : null; + var pass = (alias || (pair && !(pair.priv && pair.epriv))) && typeof args[1] === 'string' ? args[1] : null; var cb = args.filter(arg => typeof arg === 'function')[0] || null; // cb now can stand anywhere, after alias/pass or pair var opt = args && args.length > 1 && typeof args[args.length-1] === 'object' ? args[args.length-1] : {}; // opt is always the last parameter which typeof === 'object' and stands after cb @@ -1048,6 +1048,17 @@ Gun.log("Your 'auth' callback crashed with:", e); } } + act.h = function(data){ + if(!data){ return act.b() } + alias = data.alias + if(!alias) + alias = data.alias = "~" + pair.pub + if(!data.auth){ + return act.g(pair); + } + pair = null; + act.c((act.data = data).auth); + } act.z = function(){ // password update so encrypt private key using new pwd + salt act.salt = String.random(64); // pseudo-random @@ -1084,7 +1095,10 @@ act.b(tmp); } if(pair){ - act.g(pair); + if(pair.priv && pair.epriv) + act.g(pair); + else + root.get('~'+pair.pub).once(act.h); } else if(alias){ root.get('~@'+alias).once(act.a); diff --git a/sea/auth.js b/sea/auth.js index 18bcb59a..b5473d7e 100644 --- a/sea/auth.js +++ b/sea/auth.js @@ -4,7 +4,7 @@ User.prototype.auth = function(...args){ // TODO: this PR with arguments need to be cleaned up / refactored. var pair = typeof args[0] === 'object' && (args[0].pub || args[0].epub) ? args[0] : typeof args[1] === 'object' && (args[1].pub || args[1].epub) ? args[1] : null; var alias = !pair && typeof args[0] === 'string' ? args[0] : null; - var pass = alias && typeof args[1] === 'string' ? args[1] : null; + var pass = (alias || (pair && !(pair.priv && pair.epriv))) && typeof args[1] === 'string' ? args[1] : null; var cb = args.filter(arg => typeof arg === 'function')[0] || null; // cb now can stand anywhere, after alias/pass or pair var opt = args && args.length > 1 && typeof args[args.length-1] === 'object' ? args[args.length-1] : {}; // opt is always the last parameter which typeof === 'object' and stands after cb @@ -88,6 +88,17 @@ Gun.log("Your 'auth' callback crashed with:", e); } } + act.h = function(data){ + if(!data){ return act.b() } + alias = data.alias + if(!alias) + alias = data.alias = "~" + pair.pub + if(!data.auth){ + return act.g(pair); + } + pair = null; + act.c((act.data = data).auth); + } act.z = function(){ // password update so encrypt private key using new pwd + salt act.salt = String.random(64); // pseudo-random @@ -124,7 +135,10 @@ act.b(tmp); } if(pair){ - act.g(pair); + if(pair.priv && pair.epriv) + act.g(pair); + else + root.get('~'+pair.pub).once(act.h); } else if(alias){ root.get('~@'+alias).once(act.a); @@ -140,4 +154,4 @@ }catch(e){o={}}; return o; } - \ No newline at end of file + diff --git a/test/sea/sea.js b/test/sea/sea.js index 1e97b6f7..2d293bdb 100755 --- a/test/sea/sea.js +++ b/test/sea/sea.js @@ -331,6 +331,15 @@ describe('SEA', function(){ }) }) + it('logout, login via {pub}', function(done){ + var pub = user.is.pub; + user.leave(); + user.auth({pub:pub}, 'testing123', function(ack){ + expect(ack.err).to.not.be.ok(); + done(); + }) + }) + it('save data', function(done){ user.get('a').get('b').put(0, function(ack){ expect(ack.err).to.not.be.ok(); @@ -765,3 +774,4 @@ describe('SEA', function(){ }) }()); +