From dbf4be27ea595deb80e34e7c123b1fb9c0da6173 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Mon, 24 Jun 2024 15:53:23 +0100 Subject: [PATCH] fix: SAML: invalid_code issue, missing user error signing up (#15522) * fix: Error thrown due to missing user * chore: Remove unnecessary logs * fix: Remove PageWrapper in order to prevent double signIn * Change profile typing to optional * further type fix * further type fix.. --- apps/web/pages/auth/saml-idp.tsx | 3 --- packages/app-store/_utils/installation.ts | 2 +- packages/features/auth/lib/next-auth-options.ts | 5 +---- packages/features/ee/organizations/pages/organization.tsx | 2 +- packages/types/next-auth.d.ts | 2 +- 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/apps/web/pages/auth/saml-idp.tsx b/apps/web/pages/auth/saml-idp.tsx index 6942574a60e81a..661980fa686cc2 100644 --- a/apps/web/pages/auth/saml-idp.tsx +++ b/apps/web/pages/auth/saml-idp.tsx @@ -3,8 +3,6 @@ import { useEffect } from "react"; import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams"; -import PageWrapper from "@components/PageWrapper"; - // To handle the IdP initiated login flow callback export default function Page() { const searchParams = useCompatSearchParams(); @@ -21,4 +19,3 @@ export default function Page() { return null; } -Page.PageWrapper = PageWrapper; diff --git a/packages/app-store/_utils/installation.ts b/packages/app-store/_utils/installation.ts index 716d0c9c475bb5..16d45bed7ff02b 100644 --- a/packages/app-store/_utils/installation.ts +++ b/packages/app-store/_utils/installation.ts @@ -20,7 +20,7 @@ type InstallationArgs = { appType: string; user: { id: number; - profile: UserProfile; + profile?: UserProfile; }; slug: string; key?: Prisma.InputJsonValue; diff --git a/packages/features/auth/lib/next-auth-options.ts b/packages/features/auth/lib/next-auth-options.ts index a0bf241de0f567..f5a12f2cb9c289 100644 --- a/packages/features/auth/lib/next-auth-options.ts +++ b/packages/features/auth/lib/next-auth-options.ts @@ -281,9 +281,6 @@ if (isSAMLLoginEnabled) { const user = await UserRepository.findByEmailAndIncludeProfilesAndPassword({ email: profile.email || "", }); - if (!user) throw new Error(ErrorCode.UserNotFound); - - const [userProfile] = user.allProfiles; return { id: profile.id || 0, firstName: profile.firstName || "", @@ -292,7 +289,7 @@ if (isSAMLLoginEnabled) { name: `${profile.firstName || ""} ${profile.lastName || ""}`.trim(), email_verified: true, locale: profile.locale, - profile: userProfile, + ...(user ? { profile: user.allProfiles[0] } : {}), }; }, options: { diff --git a/packages/features/ee/organizations/pages/organization.tsx b/packages/features/ee/organizations/pages/organization.tsx index 16a65e377ec1e5..954cba42f37be1 100644 --- a/packages/features/ee/organizations/pages/organization.tsx +++ b/packages/features/ee/organizations/pages/organization.tsx @@ -17,7 +17,7 @@ export const getServerSideProps = async ({ req, res }: GetServerSidePropsContext // Check if logged in user has an organization assigned const session = await getServerSession({ req, res }); - if (!session?.user.profile.organizationId) { + if (!session?.user.profile?.organizationId) { return { notFound: true, }; diff --git a/packages/types/next-auth.d.ts b/packages/types/next-auth.d.ts index 438c2fa7da589b..fadae41d4acc5f 100644 --- a/packages/types/next-auth.d.ts +++ b/packages/types/next-auth.d.ts @@ -38,7 +38,7 @@ declare module "next-auth" { avatarUrl?: PrismaUser["avatarUrl"]; role?: PrismaUser["role"] | "INACTIVE_ADMIN"; locale?: string | null; - profile: UserProfile; + profile?: UserProfile; } }