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

Fix: hide unsupported login elements #11185

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 8 additions & 10 deletions src/components/structures/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,19 +392,17 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
// look for a flow where we understand all of the steps.
const supportedFlows = flows.filter(this.isSupportedFlow);

if (supportedFlows.length > 0) {
this.setState({
flows: supportedFlows,
});

if (!supportedFlows.length) {
kerryarchibald marked this conversation as resolved.
Show resolved Hide resolved
this.setState({
flows: supportedFlows,
errorText: _t(
"This homeserver doesn't offer any login flows that are supported by this client.",
),
});
return;
}

// we got to the end of the list without finding a suitable flow.
this.setState({
errorText: _t(
"This homeserver doesn't offer any login flows which are supported by this client.",
),
});
},
(err) => {
this.setState({
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3565,7 +3565,7 @@
"General failure": "General failure",
"This homeserver does not support login using email address.": "This homeserver does not support login using email address.",
"Failed to perform homeserver discovery": "Failed to perform homeserver discovery",
"This homeserver doesn't offer any login flows which are supported by this client.": "This homeserver doesn't offer any login flows which are supported by this client.",
"This homeserver doesn't offer any login flows that are supported by this client.": "This homeserver doesn't offer any login flows that are supported by this client.",
"Syncing…": "Syncing…",
"Signing In…": "Signing In…",
"If you've joined lots of rooms, this might take a while": "If you've joined lots of rooms, this might take a while",
Expand Down
34 changes: 33 additions & 1 deletion test/components/structures/auth/Login-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,38 @@ describe("Login", function () {
expect(platform.startSingleSignOn.mock.calls[1][0].baseUrl).toBe("https://server2");
});

it("should handle updating to a server with no supported flows", async () => {
mockClient.loginFlows.mockResolvedValue({
flows: [
{
type: "m.login.sso",
},
],
});

const { container, rerender } = render(getRawComponent());
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

// update the mock for the new server with no supported flows
mockClient.loginFlows.mockResolvedValue({
flows: [
{
type: "just something weird",
},
],
});
// render with a new server
rerender(getRawComponent("https://server2"));
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

expect(
screen.getByText("This homeserver doesn't offer any login flows that are supported by this client."),
).toBeInTheDocument();

// no sso button because server2 doesnt support sso
expect(container.querySelector(".mx_SSOButton")).not.toBeInTheDocument();
});

it("should show single Continue button if OIDC MSC3824 compatibility is given by server", async () => {
mockClient.loginFlows.mockResolvedValue({
flows: [
Expand Down Expand Up @@ -285,7 +317,7 @@ describe("Login", function () {
await waitForElementToBeRemoved(() => screen.queryAllByLabelText("Loading…"));

expect(
screen.getByText("This homeserver doesn't offer any login flows which are supported by this client."),
screen.getByText("This homeserver doesn't offer any login flows that are supported by this client."),
).toBeInTheDocument();
});

Expand Down