Fix ScalarAuthClient to refresh tokens if they fail
Also add a test to make sure it does it
This commit is contained in:
parent
99d1ed5efe
commit
69fa34d71f
2 changed files with 63 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue