resolve promise on pair

This commit is contained in:
AJ ONeal 2018-06-21 19:48:04 +00:00
parent 06b894a99d
commit a9353a9a75
1 changed files with 14 additions and 2 deletions

View File

@ -203,6 +203,9 @@ module.exports.pairPin = function (opts) {
var pathname = path.join(__dirname, 'emails', auth.subject + '.' + hrname + '.data');
auth.authz = jwt.sign(authzData, state.secret);
authzData.jwt = auth.authz;
if (auth.resolve) {
auth.resolve(auth);
}
fs.writeFile(pathname, JSON.stringify(authzData), function (err) {
if (err) {
console.error('[ERROR] in writing token details');
@ -237,8 +240,17 @@ module.exports.authenticate = function (opts) {
// multiple times (or something else goes wrong)
// this will cause the websocket to disconnect
auth.resolve = resolve;
auth.reject = reject;
auth.resolve = function (auth) {
opts.auth = auth.authz;
auth.resolve = null;
auth.reject = null;
return state.defaults.authenticate(opts.auth).then(resolve);
};
auth.reject = function (err) {
auth.resolve = null;
auth.reject = null;
reject(err);
};
});
return auth.promise;