Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix Identity Server terms accepting not working as expected (#12109)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy authored Jan 8, 2024
1 parent 578ae36 commit 35e99d6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/IdentityAuthClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -117,10 +122,10 @@ export default class IdentityAuthClient {
}

private async checkToken(token: string): Promise<void> {
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");
Expand Down Expand Up @@ -171,7 +176,8 @@ export default class IdentityAuthClient {
public async registerForToken(check = true): Promise<string> {
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;
Expand Down

0 comments on commit 35e99d6

Please sign in to comment.