From 0d53db787710de8db30fabc6bca82d71973c3dad Mon Sep 17 00:00:00 2001 From: Pavel Diatchenko Date: Wed, 10 Jun 2020 14:45:18 +1200 Subject: [PATCH 1/4] Fixed error "Gun.log.once is not a function". --- lib/stats.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/stats.js b/lib/stats.js index 2be3c618..9775d2f2 100644 --- a/lib/stats.js +++ b/lib/stats.js @@ -74,4 +74,5 @@ Gun.log = console.STAT = function(a,b,c,d){ } if(!console.LOG || log.off){ return a } return log.apply(Gun, arguments); -} \ No newline at end of file +} +Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++ || Gun.log(s) }; From 823df19593a3b49732716ab0395e1a0aba116f7a Mon Sep 17 00:00:00 2001 From: MIMIZA Date: Sat, 13 Jun 2020 11:55:19 +0700 Subject: [PATCH 2/4] Fix sea.js issues #962, #957, #956 BEFORE: - user.recall() uses alias/pass -> not reliable, only works with auth(alias,pass), doesn't work with auth(pair) - user.auth(pair, cb) -> cb is not a function AFTER: - user.recall() uses pair -> more reliable, works with auth(pair) - user.auth(pair, cb) -> works --- sea.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/sea.js b/sea.js index 280847b5..2ea8d001 100644 --- a/sea.js +++ b/sea.js @@ -825,16 +825,21 @@ return gun; } // now that we have created a user, we want to authenticate them! - User.prototype.auth = function(alias, pass, cb, opt){ + User.prototype.auth = function(...args){ + const alias = typeof args[0] === 'string' ? args[0] : null + const pass = alias && typeof args[1] === 'string' ? args[1] : null + const 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 + const cb = args.filter(arg => typeof arg === 'function')[0] || function(){} // cb now can stand anywhere, after alias/pass or pair + const 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 + var gun = this, cat = (gun._), root = gun.back(-1); - cb = cb || function(){}; + if(cat.ing){ cb({err: Gun.log("User is already being created or authenticated!"), wait: true}); return gun; } cat.ing = true; - opt = opt || {}; - var pair = (alias && (alias.pub || alias.epub))? alias : (pass && (pass.pub || pass.epub))? pass : null; + var act = {}, u; act.a = function(data){ if(!data){ return act.b() } @@ -896,8 +901,7 @@ try{var sS = {}; sS = window.sessionStorage; sS.recall = true; - sS.alias = alias; - sS.tmp = pass; + sS.pair = JSON.stringify(pair); // auth using pair is more reliable than alias/pass }catch(e){} } try{ @@ -969,9 +973,8 @@ if(SEA.window){ try{var sS = {}; sS = window.sessionStorage; - delete sS.alias; - delete sS.tmp; delete sS.recall; + delete sS.pair; }catch(e){}; } return gun; @@ -995,7 +998,7 @@ return gun; } User.prototype.recall = function(opt, cb){ - var gun = this, root = gun.back(-1), tmp; + var gun = this, root = gun.back(-1); opt = opt || {}; if(opt && opt.sessionStorage){ if(SEA.window){ @@ -1004,8 +1007,8 @@ if(sS){ (root._).opt.remember = true; ((gun.back('user')._).opt||opt).remember = true; - if(sS.recall || (sS.alias && sS.tmp)){ - root.user().auth(sS.alias, sS.tmp, cb); + if(sS.recall || sS.pair){ + root.user().auth(JSON.parse(sS.pair), cb); // pair is more reliable than alias/pass } } }catch(e){} From 486184e7670e43467f7e53d6649ff3a0bd47cd32 Mon Sep 17 00:00:00 2001 From: MIMIZA Date: Mon, 15 Jun 2020 08:32:22 +0700 Subject: [PATCH 3/4] Switch to ancient technique ES6 might not be reliable, so I decided to switch back to ancient JS. Removed spread operator (...args), replaced with "arguments" --- sea.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sea.js b/sea.js index 2ea8d001..133003df 100644 --- a/sea.js +++ b/sea.js @@ -825,13 +825,13 @@ return gun; } // now that we have created a user, we want to authenticate them! - User.prototype.auth = function(...args){ - const alias = typeof args[0] === 'string' ? args[0] : null - const pass = alias && typeof args[1] === 'string' ? args[1] : null - const 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 - const cb = args.filter(arg => typeof arg === 'function')[0] || function(){} // cb now can stand anywhere, after alias/pass or pair - const 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 - + User.prototype.auth = function(){ + const alias = typeof arguments[0] === 'string' ? arguments[0] : null + const pass = alias && typeof arguments[1] === 'string' ? arguments[1] : null + const pair = typeof arguments[0] === 'object' && (arguments[0].pub || arguments[0].epub) ? arguments[0] : typeof arguments[1] === 'object' && (arguments[1].pub || arguments[1].epub) ? arguments[1] : null + const cb = Array.prototype.slice.call(arguments).filter(arg => typeof arg === 'function')[0] || function(){} // cb now can stand anywhere, after alias/pass or pair + const opt = arguments && arguments.length > 1 && typeof arguments[arguments.length-1] === 'object' ? arguments[arguments.length-1] : {} // opt is always the last parameter which typeof === 'object' and stands after cb + console.log({alias,pass,pair,cb,opt}) var gun = this, cat = (gun._), root = gun.back(-1); if(cat.ing){ From e88a120a4e273fdb412bf20716f822f1735d8d7d Mon Sep 17 00:00:00 2001 From: MIMIZA Date: Mon, 15 Jun 2020 08:40:00 +0700 Subject: [PATCH 4/4] remove console.log --- sea.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sea.js b/sea.js index 133003df..df43f647 100644 --- a/sea.js +++ b/sea.js @@ -831,7 +831,7 @@ const pair = typeof arguments[0] === 'object' && (arguments[0].pub || arguments[0].epub) ? arguments[0] : typeof arguments[1] === 'object' && (arguments[1].pub || arguments[1].epub) ? arguments[1] : null const cb = Array.prototype.slice.call(arguments).filter(arg => typeof arg === 'function')[0] || function(){} // cb now can stand anywhere, after alias/pass or pair const opt = arguments && arguments.length > 1 && typeof arguments[arguments.length-1] === 'object' ? arguments[arguments.length-1] : {} // opt is always the last parameter which typeof === 'object' and stands after cb - console.log({alias,pass,pair,cb,opt}) + var gun = this, cat = (gun._), root = gun.back(-1); if(cat.ing){