From 35e99d69d30d9df6d1b93a496bf57b74837490fd Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 8 Jan 2024 10:27:03 +0000 Subject: [PATCH] Fix Identity Server terms accepting not working as expected (#12109) Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/IdentityAuthClient.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/IdentityAuthClient.tsx b/src/IdentityAuthClient.tsx index e4bbb76705..9dc6ebd843 100644 --- a/src/IdentityAuthClient.tsx +++ b/src/IdentityAuthClient.tsx @@ -57,8 +57,13 @@ export default class IdentityAuthClient { } } + // This client must not be used for general operations as it may not have a baseUrl or be running (tempClient). + private get identityClient(): MatrixClient { + return this.tempClient ?? this.matrixClient; + } + private get matrixClient(): MatrixClient { - return this.tempClient ? this.tempClient : MatrixClientPeg.safeGet(); + return MatrixClientPeg.safeGet(); } private writeToken(): void { @@ -117,10 +122,10 @@ export default class IdentityAuthClient { } private async checkToken(token: string): Promise { - const identityServerUrl = this.matrixClient.getIdentityServerUrl()!; + const identityServerUrl = this.identityClient.getIdentityServerUrl()!; try { - await this.matrixClient.getIdentityAccount(token); + await this.identityClient.getIdentityAccount(token); } catch (e) { if (e instanceof MatrixError && e.errcode === "M_TERMS_NOT_SIGNED") { logger.log("Identity server requires new terms to be agreed to"); @@ -171,7 +176,8 @@ export default class IdentityAuthClient { public async registerForToken(check = true): Promise { const hsOpenIdToken = await MatrixClientPeg.safeGet().getOpenIdToken(); // XXX: The spec is `token`, but we used `access_token` for a Sydent release. - const { access_token: accessToken, token } = await this.matrixClient.registerWithIdentityServer(hsOpenIdToken); + const { access_token: accessToken, token } = + await this.identityClient.registerWithIdentityServer(hsOpenIdToken); const identityAccessToken = token ? token : accessToken; if (check) await this.checkToken(identityAccessToken); return identityAccessToken;