diff --git a/CHANGELOG.md b/CHANGELOG.md index f37fea380fb68ca8b7c2ecdc5fc1043bfd9537fe..3ca620ebec0b1bc77a63ce068557a032fb57aec8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- Wait for authentication to complete for fast polling rates + ### Changed - Add hyphen to regex for schema version to enable issue branches diff --git a/dist/adapter.esm.js b/dist/adapter.esm.js index 862552155c8e296fb791c512cac2c438de251a06..22e9c0a2d1551c9d5a2cb53676a059c634123b3d 100644 --- a/dist/adapter.esm.js +++ b/dist/adapter.esm.js @@ -8,6 +8,7 @@ class Adapter { this.protocol = protocol; this.config = config; this.axios = axios; + this.authenticating = false; } /** @@ -44,6 +45,10 @@ class Adapter { * @returns {object} */ getAuthorizationHeader() { + if (this.authenticating) { + // return an pseudo response with an ignored status + return Promise.reject({ response: { status: 405 } }); + } if (!this.tokenValid()) return this.auth().then((response) => { return { @@ -62,6 +67,7 @@ class Adapter { * @returns {object} */ auth() { + this.authenticating = true; let adapterConfig = this.config; return this.axios .get(`${adapterConfig.api}/token`, { @@ -72,9 +78,11 @@ class Adapter { }) .then((response) => { this.credentials = response.data; + this.authenticating = false; return response; }) .catch((error) => { + this.authenticating = false; return Promise.reject(error); }); } @@ -116,6 +124,7 @@ class Adapter { retry = true; } break; + // ignore 405 from auth in progress case 503: { retry = true; } diff --git a/dist/adapter.js b/dist/adapter.js index c1f0e28e2fa62fdf78acd646cc8f3f4a54c08c85..868a47cf41591f29c0ced47e26788559d1d1d6c3 100644 --- a/dist/adapter.js +++ b/dist/adapter.js @@ -10,6 +10,7 @@ class Adapter { this.protocol = protocol; this.config = config; this.axios = axios; + this.authenticating = false; } /** @@ -46,6 +47,10 @@ class Adapter { * @returns {object} */ getAuthorizationHeader() { + if (this.authenticating) { + // return an pseudo response with an ignored status + return Promise.reject({ response: { status: 405 } }); + } if (!this.tokenValid()) return this.auth().then((response) => { return { @@ -64,6 +69,7 @@ class Adapter { * @returns {object} */ auth() { + this.authenticating = true; let adapterConfig = this.config; return this.axios .get(`${adapterConfig.api}/token`, { @@ -74,9 +80,11 @@ class Adapter { }) .then((response) => { this.credentials = response.data; + this.authenticating = false; return response; }) .catch((error) => { + this.authenticating = false; return Promise.reject(error); }); } @@ -118,6 +126,7 @@ class Adapter { retry = true; } break; + // ignore 405 from auth in progress case 503: { retry = true; } diff --git a/src/adapter/index.js b/src/adapter/index.js index ef71cc39fbd2d8adfb931f29db5a08adfe2f45c7..fba52314a4b40f2633f5d6909cc1384417d747c8 100644 --- a/src/adapter/index.js +++ b/src/adapter/index.js @@ -8,6 +8,7 @@ export class Adapter { this.protocol = protocol; this.config = config; this.axios = axios; + this.authenticating = false; } /** @@ -44,6 +45,10 @@ export class Adapter { * @returns {object} */ getAuthorizationHeader() { + if (this.authenticating) { + // return an pseudo response with an ignored status + return Promise.reject({ response: { status: 405 } }); + } if (!this.tokenValid()) return this.auth().then((response) => { return { @@ -62,6 +67,7 @@ export class Adapter { * @returns {object} */ auth() { + this.authenticating = true; let adapterConfig = this.config; return this.axios .get(`${adapterConfig.api}/token`, { @@ -72,9 +78,11 @@ export class Adapter { }) .then((response) => { this.credentials = response.data; + this.authenticating = false; return response; }) .catch((error) => { + this.authenticating = false; return Promise.reject(error); }); } @@ -116,6 +124,7 @@ export class Adapter { retry = true; } break; + // ignore 405 from auth in progress case 503: { retry = true; }