Skip to content

Commit

Permalink
[bugfix][connection] fix client promise (apache-superset#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
williaster authored Dec 7, 2018
1 parent 5f4f13d commit 0ab21ac
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/superset-ui-connection/src/SupersetClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export interface ClientConfig {

class SupersetClient {
credentials: Credentials;
csrfToken: CsrfToken | undefined;
csrfPromise: CsrfPromise;
csrfToken?: CsrfToken;
csrfPromise?: CsrfPromise;
protocol: Protocol;
host: Host;
headers: Headers;
Expand All @@ -49,12 +49,7 @@ class SupersetClient {
this.protocol = protocol;
this.credentials = credentials;
this.csrfToken = csrfToken;
this.csrfPromise = Promise.reject({
error: `SupersetClient has no CSRF token, ensure it is initialized or
try logging into the Superset instance at ${this.getUrl({
endpoint: '/login',
})}`,
});
this.csrfPromise = undefined;

if (typeof this.csrfToken === 'string') {
this.headers = { ...this.headers, 'X-CSRFToken': this.csrfToken };
Expand Down Expand Up @@ -132,7 +127,15 @@ class SupersetClient {
}

ensureAuth() {
return this.csrfPromise;
return (
this.csrfPromise ||
Promise.reject({
error: `SupersetClient has no CSRF token, ensure it is initialized or
try logging into the Superset instance at ${this.getUrl({
endpoint: '/login',
})}`,
})
);
}

async getCSRFToken() {
Expand Down

0 comments on commit 0ab21ac

Please sign in to comment.