From b5cf4e50a953f24c4080e925a64dc623f334bd0f Mon Sep 17 00:00:00 2001 From: Kiran K Date: Mon, 9 Oct 2023 21:00:30 +0530 Subject: [PATCH] fix: Hide SAML/OIDC login button if no sso connection exists (Self hosted instance) (#10903) Co-authored-by: zomars Co-authored-by: Peer Richelsen Co-authored-by: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> --- apps/web/pages/auth/login.tsx | 17 ++++++++-- apps/web/playwright/login.oauth.e2e.ts | 7 +++-- .../server/routers/publicViewer/_router.tsx | 7 +++++ .../publicViewer/ssoConnections.handler.ts | 31 +++++++++++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 packages/trpc/server/routers/publicViewer/ssoConnections.handler.ts diff --git a/apps/web/pages/auth/login.tsx b/apps/web/pages/auth/login.tsx index de15f84e4e..a5e5168905 100644 --- a/apps/web/pages/auth/login.tsx +++ b/apps/web/pages/auth/login.tsx @@ -15,11 +15,12 @@ import { SAMLLogin } from "@calcom/features/auth/SAMLLogin"; import { ErrorCode } from "@calcom/features/auth/lib/ErrorCode"; import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; import { isSAMLLoginEnabled, samlProductID, samlTenantID } from "@calcom/features/ee/sso/lib/saml"; -import { WEBAPP_URL, WEBSITE_URL } from "@calcom/lib/constants"; +import { WEBAPP_URL, WEBSITE_URL, HOSTED_CAL_FEATURES } from "@calcom/lib/constants"; import { getSafeRedirectUrl } from "@calcom/lib/getSafeRedirectUrl"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@calcom/lib/telemetry"; import prisma from "@calcom/prisma"; +import { trpc } from "@calcom/trpc/react"; import { Alert, Button, EmailField, PasswordField } from "@calcom/ui"; import { ArrowLeft, Lock } from "@calcom/ui/components/icon"; @@ -160,6 +161,16 @@ export default function Login({ else setErrorMessage(errorMessages[res.error] || t("something_went_wrong")); }; + const { data, isLoading } = trpc.viewer.public.ssoConnections.useQuery(undefined, { + onError: (err) => { + setErrorMessage(err.message); + }, + }); + + const displaySSOLogin = HOSTED_CAL_FEATURES + ? true + : isSAMLLoginEnabled && !isLoading && data?.connectionExists; + return (
{!twoFactorRequired && ( <> - {(isGoogleLoginEnabled || isSAMLLoginEnabled) &&
} + {(isGoogleLoginEnabled || displaySSOLogin) &&
}
{isGoogleLoginEnabled && (