Skip to content

Commit dbf4be2

Browse files
authored
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..
1 parent 7b69a6a commit dbf4be2

File tree

5 files changed

+4
-10
lines changed

5 files changed

+4
-10
lines changed

apps/web/pages/auth/saml-idp.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { useEffect } from "react";
33

44
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
55

6-
import PageWrapper from "@components/PageWrapper";
7-
86
// To handle the IdP initiated login flow callback
97
export default function Page() {
108
const searchParams = useCompatSearchParams();
@@ -21,4 +19,3 @@ export default function Page() {
2119

2220
return null;
2321
}
24-
Page.PageWrapper = PageWrapper;

packages/app-store/_utils/installation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type InstallationArgs = {
2020
appType: string;
2121
user: {
2222
id: number;
23-
profile: UserProfile;
23+
profile?: UserProfile;
2424
};
2525
slug: string;
2626
key?: Prisma.InputJsonValue;

packages/features/auth/lib/next-auth-options.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@ if (isSAMLLoginEnabled) {
281281
const user = await UserRepository.findByEmailAndIncludeProfilesAndPassword({
282282
email: profile.email || "",
283283
});
284-
if (!user) throw new Error(ErrorCode.UserNotFound);
285-
286-
const [userProfile] = user.allProfiles;
287284
return {
288285
id: profile.id || 0,
289286
firstName: profile.firstName || "",
@@ -292,7 +289,7 @@ if (isSAMLLoginEnabled) {
292289
name: `${profile.firstName || ""} ${profile.lastName || ""}`.trim(),
293290
email_verified: true,
294291
locale: profile.locale,
295-
profile: userProfile,
292+
...(user ? { profile: user.allProfiles[0] } : {}),
296293
};
297294
},
298295
options: {

packages/features/ee/organizations/pages/organization.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const getServerSideProps = async ({ req, res }: GetServerSidePropsContext
1717
// Check if logged in user has an organization assigned
1818
const session = await getServerSession({ req, res });
1919

20-
if (!session?.user.profile.organizationId) {
20+
if (!session?.user.profile?.organizationId) {
2121
return {
2222
notFound: true,
2323
};

packages/types/next-auth.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ declare module "next-auth" {
3838
avatarUrl?: PrismaUser["avatarUrl"];
3939
role?: PrismaUser["role"] | "INACTIVE_ADMIN";
4040
locale?: string | null;
41-
profile: UserProfile;
41+
profile?: UserProfile;
4242
}
4343
}
4444

0 commit comments

Comments
 (0)