diff --git a/src/Login.ts b/src/Login.ts index f7b188c64ac..a16f570fa90 100644 --- a/src/Login.ts +++ b/src/Login.ts @@ -51,7 +51,7 @@ export interface IIdentityProvider { export interface ISSOFlow { type: "m.login.sso" | "m.login.cas"; // eslint-disable-next-line camelcase - identity_providers: IIdentityProvider[]; + identity_providers?: IIdentityProvider[]; } export type LoginFlow = ISSOFlow | IPasswordFlow; diff --git a/src/components/views/elements/SSOButtons.tsx b/src/components/views/elements/SSOButtons.tsx index b11e74e1e27..16f860792bb 100644 --- a/src/components/views/elements/SSOButtons.tsx +++ b/src/components/views/elements/SSOButtons.tsx @@ -29,7 +29,7 @@ import { mediaFromMxc } from "../../../customisations/Media"; import { PosthogAnalytics } from "../../../PosthogAnalytics"; interface ISSOButtonProps extends Omit { - idp: IIdentityProvider; + idp?: IIdentityProvider; mini?: boolean; } @@ -84,7 +84,7 @@ const SSOButton: React.FC = ({ const label = idp ? _t("Continue with %(provider)s", { provider: idp.name }) : _t("Sign in with single sign-on"); const onClick = () => { - const authenticationType = getAuthenticationType(idp.brand); + const authenticationType = getAuthenticationType(idp?.brand ?? ""); PosthogAnalytics.instance.setAuthenticationType(authenticationType); PlatformPeg.get().startSingleSignOn(matrixClient, loginType, fragmentAfterLogin, idp?.id); }; diff --git a/test/components/structures/auth/Login-test.tsx b/test/components/structures/auth/Login-test.tsx index af7e2599f0b..44c44ffd26b 100644 --- a/test/components/structures/auth/Login-test.tsx +++ b/test/components/structures/auth/Login-test.tsx @@ -146,4 +146,19 @@ describe('Login', function() { const ssoButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, "mx_SSOButton"); expect(ssoButtons.length).toBe(3); }); + + it("should show single SSO button if identity_providers is null", async () => { + mockClient.loginFlows.mockResolvedValue({ + flows: [{ + "type": "m.login.sso", + }], + }); + + const root = render(); + + await flushPromises(); + + const ssoButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, "mx_SSOButton"); + expect(ssoButtons.length).toBe(1); + }); });