From c6a690d1fbd485de5ec7707fd17a7e1d45110240 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Wed, 25 Oct 2023 17:32:19 +1300 Subject: [PATCH] allow relogin from softlogout when loginToken is present --- cypress/e2e/login/soft_logout.spec.ts | 3 --- src/components/structures/auth/SoftLogout.tsx | 23 +++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cypress/e2e/login/soft_logout.spec.ts b/cypress/e2e/login/soft_logout.spec.ts index 959197b7ebe..43b3b039005 100644 --- a/cypress/e2e/login/soft_logout.spec.ts +++ b/cypress/e2e/login/soft_logout.spec.ts @@ -72,9 +72,6 @@ describe("Soft logout", () => { }); it("shows the soft-logout page when a request fails, and allows a re-login", () => { - // there is a bug in Element which means this only actually works if there is an app reload between - // the token login and the soft-logout: https://github.com/vector-im/element-web/issues/25957 - cy.reload(); cy.findByRole("heading", { name: "Welcome Alice" }); interceptRequestsWithSoftLogout(); diff --git a/src/components/structures/auth/SoftLogout.tsx b/src/components/structures/auth/SoftLogout.tsx index 250c6a6a1d3..f623ae7dcbb 100644 --- a/src/components/structures/auth/SoftLogout.tsx +++ b/src/components/structures/auth/SoftLogout.tsx @@ -114,8 +114,9 @@ export default class SoftLogout extends React.Component { const hasAllParams = queryParams?.["loginToken"]; if (hasAllParams) { this.setState({ loginView: LoginView.Loading }); - this.trySsoLogin(); - return; + + const loggedIn = await this.trySsoLogin(); + if (loggedIn) return; } // Note: we don't use the existing Login class because it is heavily flow-based. We don't @@ -183,14 +184,18 @@ export default class SoftLogout extends React.Component { }); }; - private async trySsoLogin(): Promise { + /** + * Attempt to login via SSO + * @returns A promise that resolves to a boolean - true when sso login was successful + */ + private async trySsoLogin(): Promise { this.setState({ busy: true }); const hsUrl = localStorage.getItem(SSO_HOMESERVER_URL_KEY); if (!hsUrl) { logger.error("Homeserver URL unknown for SSO login callback"); this.setState({ busy: false, loginView: LoginView.Unsupported }); - return; + return false; } const isUrl = localStorage.getItem(SSO_ID_SERVER_URL_KEY) || MatrixClientPeg.safeGet().getIdentityServerUrl(); @@ -206,16 +211,20 @@ export default class SoftLogout extends React.Component { } catch (e) { logger.error(e); this.setState({ busy: false, loginView: LoginView.Unsupported }); - return; + return false; } - Lifecycle.hydrateSession(credentials) + return Lifecycle.hydrateSession(credentials) .then(() => { - if (this.props.onTokenLoginCompleted) this.props.onTokenLoginCompleted(); + if (this.props.onTokenLoginCompleted) { + this.props.onTokenLoginCompleted(); + } + return true; }) .catch((e) => { logger.error(e); this.setState({ busy: false, loginView: LoginView.Unsupported }); + return false; }); }