allow relogin from softlogout when loginToken is present (#11794)
parent
48a89a236a
commit
e8b27403b7
|
@ -72,9 +72,6 @@ describe("Soft logout", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows the soft-logout page when a request fails, and allows a re-login", () => {
|
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" });
|
cy.findByRole("heading", { name: "Welcome Alice" });
|
||||||
|
|
||||||
interceptRequestsWithSoftLogout();
|
interceptRequestsWithSoftLogout();
|
||||||
|
|
|
@ -114,8 +114,9 @@ export default class SoftLogout extends React.Component<IProps, IState> {
|
||||||
const hasAllParams = queryParams?.["loginToken"];
|
const hasAllParams = queryParams?.["loginToken"];
|
||||||
if (hasAllParams) {
|
if (hasAllParams) {
|
||||||
this.setState({ loginView: LoginView.Loading });
|
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
|
// 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 });
|
this.setState({ busy: true });
|
||||||
|
|
||||||
const hsUrl = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
|
const hsUrl = localStorage.getItem(SSO_HOMESERVER_URL_KEY);
|
||||||
if (!hsUrl) {
|
if (!hsUrl) {
|
||||||
logger.error("Homeserver URL unknown for SSO login callback");
|
logger.error("Homeserver URL unknown for SSO login callback");
|
||||||
this.setState({ busy: false, loginView: LoginView.Unsupported });
|
this.setState({ busy: false, loginView: LoginView.Unsupported });
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isUrl = localStorage.getItem(SSO_ID_SERVER_URL_KEY) || MatrixClientPeg.safeGet().getIdentityServerUrl();
|
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) {
|
} catch (e) {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
this.setState({ busy: false, loginView: LoginView.Unsupported });
|
this.setState({ busy: false, loginView: LoginView.Unsupported });
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Lifecycle.hydrateSession(credentials)
|
return Lifecycle.hydrateSession(credentials)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.props.onTokenLoginCompleted) this.props.onTokenLoginCompleted();
|
if (this.props.onTokenLoginCompleted) {
|
||||||
|
this.props.onTokenLoginCompleted();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
this.setState({ busy: false, loginView: LoginView.Unsupported });
|
this.setState({ busy: false, loginView: LoginView.Unsupported });
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue