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..
This commit is contained in:
Alex van Andel
2024-06-24 14:53:23 +00:00
committed by GitHub
parent 7b69a6ab9c
commit dbf4be27ea
5 changed files with 4 additions and 10 deletions
-3
View File
@@ -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;
+1 -1
View File
@@ -20,7 +20,7 @@ type InstallationArgs = {
appType: string;
user: {
id: number;
profile: UserProfile;
profile?: UserProfile;
};
slug: string;
key?: Prisma.InputJsonValue;
@@ -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: {
@@ -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,
};
+1 -1
View File
@@ -38,7 +38,7 @@ declare module "next-auth" {
avatarUrl?: PrismaUser["avatarUrl"];
role?: PrismaUser["role"] | "INACTIVE_ADMIN";
locale?: string | null;
profile: UserProfile;
profile?: UserProfile;
}
}