fix: sign upsert error (#25437)

This commit is contained in:
Udit Takkar authored and GitHub committed 2025-11-27 12:33:29 -05:00
1 parent 3af6fee05d
commit 179ace23e1
2 files changed
+6

No files matched your search

@@ -154,6 +154,7 @@ const handler: CustomNextApiHandler = async (body, usernameStatus) => {
}, },
}); });
if (team) { if (team) {
const organizationId = team.isOrganization ? team.id : team.parent?.id ?? null;
const user = await prisma.user.upsert({ const user = await prisma.user.upsert({
where: { email }, where: { email },
update: { update: {
@@ -166,12 +167,14 @@ const handler: CustomNextApiHandler = async (body, usernameStatus) => {
update: { hash: hashedPassword }, update: { hash: hashedPassword },
}, },
}, },
organizationId,
}, },
create: { create: {
username, username,
email, email,
identityProvider: IdentityProvider.CAL, identityProvider: IdentityProvider.CAL,
password: { create: { hash: hashedPassword } }, password: { create: { hash: hashedPassword } },
organizationId,
}, },
}); });
// Wrapping in a transaction as if one fails we want to rollback the whole thing to preventa any data inconsistencies // Wrapping in a transaction as if one fails we want to rollback the whole thing to preventa any data inconsistencies
@@ -88,6 +88,7 @@ export default async function handler(body: Record<string, string>) {
} }
} }
const organizationId = team.isOrganization ? team.id : team.parent?.id ?? null;
const user = await prisma.user.upsert({ const user = await prisma.user.upsert({
where: { email: userEmail }, where: { email: userEmail },
update: { update: {
@@ -100,12 +101,14 @@ export default async function handler(body: Record<string, string>) {
}, },
emailVerified: new Date(Date.now()), emailVerified: new Date(Date.now()),
identityProvider: IdentityProvider.CAL, identityProvider: IdentityProvider.CAL,
organizationId,
}, },
create: { create: {
username: correctedUsername, username: correctedUsername,
email: userEmail, email: userEmail,
password: { create: { hash: hashedPassword } }, password: { create: { hash: hashedPassword } },
identityProvider: IdentityProvider.CAL, identityProvider: IdentityProvider.CAL,
organizationId,
}, },
}); });