From 4f2948d0f0f6d08a84d5ad0750ab390bf0715a5e Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 4 Aug 2018 10:36:27 +0000 Subject: [PATCH] bugfixes --- lib/extensions/index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/extensions/index.js b/lib/extensions/index.js index 9ed9727..a6bd1a9 100644 --- a/lib/extensions/index.js +++ b/lib/extensions/index.js @@ -188,13 +188,13 @@ DB.ports._add = function (acc, number) { }); }; DB._save = function () { - return sfs.writeAsync('./accounts.json', JSON.stringify(DB._perms)); + return sfs.writeFileAsync('./accounts.json', JSON.stringify(DB._perms)); }; DB._saveToken = null; DB._savePromises = []; DB._savePromise = PromiseA.resolve(); DB.save = function () { - cancelTimeout(DB._saveToken); + clearTimeout(DB._saveToken); return new Promise(function (resolve, reject) { function doSave() { DB._savePromise = DB._savePromise.then(function () { @@ -214,7 +214,7 @@ DB.save = function () { } DB._saveToken = setTimeout(doSave, 2500); - DB.savePromises.push({ resolve: resolve, reject: reject }); + DB._savePromises.push({ resolve: resolve, reject: reject }); }); }; @@ -917,7 +917,7 @@ Accounts._associateEmails = function (req) { // oauth3.org, issuer@oauth3.org, profile return OAUTH3.request({ url: "https://api." + req.auth.data.iss + "/api/issuer@oauth3.org/acl/profile" - , session: { accessToken: req.auth.jwt } + , session: { accessToken: req.auth.jwt, token: req.auth.data } }).then(function (resp) { var email; var err; @@ -940,7 +940,7 @@ Accounts._associateEmails = function (req) { }; app.get('/api/telebit.cloud/account', function (req, res) { return Accounts.getOrCreate(req).then(function (acc) { - var hasEmail = subData.nodes.some(function (node) { + var hasEmail = acc.nodes.some(function (node) { return 'email' === node.type; }); function getAllGrants() { @@ -953,6 +953,8 @@ app.get('/api/telebit.cloud/account', function (req, res) { result.domains.length = 0; result.ports.length = 0; grants.forEach(function (account) { + if (!account) { return; } + console.log('grants.forEach.account: ', account); account.domains.forEach(function (d) { domainsMap[d.name] = d; }); @@ -986,6 +988,7 @@ app.get('/api/telebit.cloud/account', function (req, res) { error: { code: err.code || "E_GENERIC" , message: err.toString() + , _stack: err.stack } }); });