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> </div>
<p id="debug" style="position: fixed; bottom: 0px; color: white; height: 1em;"></p> <p id="debug" style="position: fixed; bottom: 0px; color: white; height: 1em;"></p>
<script src="../jquery.js"></script> <script src="../jquery.js"></script>
<script src="/gun.js"></script> <script src="../../../gun/gun.js"></script>
<script src="/gun/nts.js"></script> <script src="../../../gun/nts.js"></script>
<script src="/gun/lib/webrtc.js"></script> <script src="../../../gun/lib/webrtc.js"></script>
<script> <script>
// Thanks to https://github.com/dmcinnes/HTML5-Asteroids // Thanks to https://github.com/dmcinnes/HTML5-Asteroids
//var gun = Gun(); //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: {}}; var game = {gun: gun.get('example/game/space'), area: {}, ships: {}};
game.keys = {38: 'up', 37: 'left', 39: 'right', 40: 'down', 32: 'space'}; game.keys = {38: 'up', 37: 'left', 39: 'right', 40: 'down', 32: 'space'};
$(document).on('keydown', function(e){ $(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'!"); 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!"; ;"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){} try{ if(typeof common !== "undefined"){ common.exports = Gun } }catch(e){}
module.exports = Gun; module.exports = Gun;
@ -1290,7 +1290,7 @@
var cat = gun._, tmp; var cat = gun._, tmp;
if(tmp = cat.soul){ return cb(tmp, as, cat), gun } if(tmp = cat.soul){ return cb(tmp, as, cat), gun }
if(tmp = cat.link){ 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); ev.rid(msg);
var at = ((at = msg.$) && at._) || {}; var at = ((at = msg.$) && at._) || {};
tmp = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put); tmp = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put);

View File

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

31
sea.js
View File

@ -655,7 +655,7 @@
// Cheers! Tell me what you think. // Cheers! Tell me what you think.
var Gun = (SEA.window||{}).Gun || USE('./gun', 1); var Gun = (SEA.window||{}).Gun || USE('./gun', 1);
Gun.SEA = SEA; Gun.SEA = SEA;
SEA.Gun = Gun; SEA.GUN = SEA.Gun = Gun;
module.exports = SEA module.exports = SEA
})(USE, './sea'); })(USE, './sea');
@ -748,7 +748,7 @@
err = null err = null
if(SEA.window){ if(SEA.window){
var tmp = SEA.window.sessionStorage; 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.alias = alias;
SEA.window.sessionStorage.tmp = pass; SEA.window.sessionStorage.tmp = pass;
} }
@ -1213,6 +1213,26 @@
} }
cat.ing = true; 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(){ if (!pass && pin) { (async function(){
try { try {
var r = await authRecall(gunRoot, { alias: alias, pin: pin }) var r = await authRecall(gunRoot, { alias: alias, pin: pin })
@ -1224,13 +1244,6 @@
return gun; 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 { (async function(){ try {
const keys = await authenticate(alias, pass, gunRoot) const keys = await authenticate(alias, pass, gunRoot)
if (!keys) { if (!keys) {