allow relogin from softlogout when loginToken is present (#11794)

pull/28217/head
Kerry 2023-10-26 19:57:28 +13:00 committed by GitHub
parent 48a89a236a
commit e8b27403b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -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();

View File

@ -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
@ -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();
@ -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;
});
}