Token Caching now works

This commit is contained in:
Amish Shah
2015-12-14 18:06:03 +00:00
parent a122f0994e
commit 8f5722d242
7 changed files with 71 additions and 26 deletions

View File

@@ -365,7 +365,6 @@ var InternalClient = (function () {
var client = this.client;
console.log(this.tokenCacher.done);
if (!this.tokenCacher.done) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
@@ -373,7 +372,21 @@ var InternalClient = (function () {
}, 20);
});
} else {
console.log("YAA - " + this.tokenCacher.getToken(email, password));
var tk = this.tokenCacher.getToken(email, password);
if (tk) {
return new Promise(function (resolve, reject) {
_this6.client.emit("debug", "bypassed direct API login, used cached token");
_this6.state = _ConnectionState2["default"].LOGGED_IN;
_this6.token = tk;
_this6.email = email;
_this6.password = password;
return _this6.getGateway().then(function (url) {
_this6.createWS(url);
return tk;
});
});
}
}
if (this.state !== _ConnectionState2["default"].DISCONNECTED && this.state !== _ConnectionState2["default"].IDLE) {
@@ -386,6 +399,7 @@ var InternalClient = (function () {
email: email,
password: password
}).then(function (res) {
_this6.client.emit("debug", "direct API login, cached token was unavailable");
var token = res.token;
_this6.tokenCacher.setToken(email, password, token);
_this6.state = _ConnectionState2["default"].LOGGED_IN;