diff --git a/cypress/e2e/login/soft_logout.spec.ts b/cypress/e2e/login/soft_logout.spec.ts index 959197b7eb..43b3b03900 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 250c6a6a1d..f623ae7dcb 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; }); }