Fix ScalarAuthClient to refresh tokens if they fail

Also add a test to make sure it does it
This commit is contained in:
David Baker 2019-07-11 16:00:24 +01:00
parent 99d1ed5efe
commit 69fa34d71f
2 changed files with 63 additions and 2 deletions

View file

@ -51,7 +51,7 @@ class ScalarAuthClient {
return this.scalarToken != null; // undef or null
}
// Returns a scalar_token string
// Returns a promise that resolves to a scalar_token string
getScalarToken() {
let token = this.scalarToken;
if (!token) token = window.localStorage.getItem("mx_scalar_token");
@ -59,7 +59,9 @@ class ScalarAuthClient {
if (!token) {
return this.registerForToken();
} else {
return this._checkToken(token);
return this._checkToken(token).catch(() => {
return this.registerForToken();
});
}
}
@ -105,6 +107,8 @@ class ScalarAuthClient {
)]).then(() => {
return token;
});
} else {
throw e;
}
});
}