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

Fix: Unable to restore a soft-logged-out session established via SSO #11794

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions cypress/e2e/login/soft_logout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 16 additions & 7 deletions src/components/structures/auth/SoftLogout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ export default class SoftLogout extends React.Component<IProps, IState> {
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
Expand Down Expand Up @@ -183,14 +184,18 @@ export default class SoftLogout extends React.Component<IProps, IState> {
});
};

private async trySsoLogin(): Promise<void> {
/**
* Attempt to login via SSO
* @returns A promise that resolves to a boolean - true when sso login was successful
*/
private async trySsoLogin(): Promise<boolean> {
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();
Expand All @@ -206,16 +211,20 @@ export default class SoftLogout extends React.Component<IProps, IState> {
} 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;
});
}

Expand Down
Loading