Tweak control flow to avoid duplicate terms prompts
This commit is contained in:
parent
a85efe5f65
commit
7ccc218a98
1 changed files with 17 additions and 8 deletions
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
import { SERVICE_TYPES } from 'matrix-js-sdk';
|
import { SERVICE_TYPES } from 'matrix-js-sdk';
|
||||||
|
|
||||||
import MatrixClientPeg from './MatrixClientPeg';
|
import MatrixClientPeg from './MatrixClientPeg';
|
||||||
import { Service, startTermsFlow } from './Terms';
|
import { Service, startTermsFlow, TermsNotSignedError } from './Terms';
|
||||||
|
|
||||||
export default class IdentityAuthClient {
|
export default class IdentityAuthClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -43,17 +43,26 @@ export default class IdentityAuthClient {
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
token = await this.registerForToken();
|
token = await this.registerForToken();
|
||||||
this.accessToken = token;
|
if (token) {
|
||||||
window.localStorage.setItem("mx_is_access_token", token);
|
this.accessToken = token;
|
||||||
|
window.localStorage.setItem("mx_is_access_token", token);
|
||||||
|
}
|
||||||
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this._checkToken(token);
|
await this._checkToken(token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (e instanceof TermsNotSignedError) {
|
||||||
|
// Retrying won't help this
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
// Retry in case token expired
|
// Retry in case token expired
|
||||||
token = await this.registerForToken();
|
token = await this.registerForToken();
|
||||||
this.accessToken = token;
|
if (token) {
|
||||||
window.localStorage.setItem("mx_is_access_token", token);
|
this.accessToken = token;
|
||||||
|
window.localStorage.setItem("mx_is_access_token", token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
|
@ -89,8 +98,8 @@ export default class IdentityAuthClient {
|
||||||
await MatrixClientPeg.get().registerWithIdentityServer(hsOpenIdToken);
|
await MatrixClientPeg.get().registerWithIdentityServer(hsOpenIdToken);
|
||||||
await this._checkToken(identityAccessToken);
|
await this._checkToken(identityAccessToken);
|
||||||
return identityAccessToken;
|
return identityAccessToken;
|
||||||
} catch (err) {
|
} catch (e) {
|
||||||
if (err.cors === "rejected" || err.httpStatus === 404) {
|
if (e.cors === "rejected" || e.httpStatus === 404) {
|
||||||
// Assume IS only supports deprecated v1 API for now
|
// Assume IS only supports deprecated v1 API for now
|
||||||
// TODO: Remove this path once v2 is only supported version
|
// TODO: Remove this path once v2 is only supported version
|
||||||
// See https://github.com/vector-im/riot-web/issues/10443
|
// See https://github.com/vector-im/riot-web/issues/10443
|
||||||
|
@ -98,7 +107,7 @@ export default class IdentityAuthClient {
|
||||||
this.authEnabled = false;
|
this.authEnabled = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.error(err);
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue