diff --git a/packages/features/auth/signup/handlers/calcomHandler.ts b/packages/features/auth/signup/handlers/calcomHandler.ts index ff78782f34..b7e88f8fd3 100644 --- a/packages/features/auth/signup/handlers/calcomHandler.ts +++ b/packages/features/auth/signup/handlers/calcomHandler.ts @@ -15,7 +15,7 @@ import prisma from "@calcom/prisma"; import { IdentityProvider } from "@calcom/prisma/enums"; import { signupSchema, teamMetadataSchema } from "@calcom/prisma/zod-utils"; -import { joinOrganization, joinAnyChildTeamOnOrgInvite } from "../utils/organization"; +import { joinAnyChildTeamOnOrgInvite } from "../utils/organization"; import { findTokenByToken, throwIfTokenExpired, validateUsernameForTeam } from "../utils/token"; async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) { @@ -124,21 +124,29 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) { }, }); - if (teamMetadata?.isOrganization) { - await joinOrganization({ - organizationId: team.id, - userId: user.id, - }); - } + const membership = await prisma.$transaction(async (tx) => { + if (teamMetadata?.isOrganization) { + await tx.user.update({ + where: { + id: user.id, + }, + data: { + organizationId: team.id, + }, + }); + } - const membership = await prisma.membership.update({ - where: { - userId_teamId: { userId: user.id, teamId: team.id }, - }, - data: { - accepted: true, - }, + const membership = await tx.membership.update({ + where: { + userId_teamId: { userId: user.id, teamId: team.id }, + }, + data: { + accepted: true, + }, + }); + return membership; }); + closeComUpsertTeamUser(team, user, membership.role); // Accept any child team invites for orgs. diff --git a/packages/features/auth/signup/handlers/selfHostedHandler.ts b/packages/features/auth/signup/handlers/selfHostedHandler.ts index 502f9902b7..03cc8d7f98 100644 --- a/packages/features/auth/signup/handlers/selfHostedHandler.ts +++ b/packages/features/auth/signup/handlers/selfHostedHandler.ts @@ -12,7 +12,7 @@ import { IdentityProvider } from "@calcom/prisma/enums"; import { signupSchema } from "@calcom/prisma/zod-utils"; import { teamMetadataSchema } from "@calcom/prisma/zod-utils"; -import { joinAnyChildTeamOnOrgInvite, joinOrganization } from "../utils/organization"; +import { joinAnyChildTeamOnOrgInvite } from "../utils/organization"; import { findTokenByToken, throwIfTokenExpired, validateUsernameForTeam } from "../utils/token"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { @@ -66,21 +66,29 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }, }); - if (teamMetadata?.isOrganization) { - await joinOrganization({ - organizationId: team.id, - userId: user.id, - }); - } + const membership = await prisma.$transaction(async (tx) => { + if (teamMetadata?.isOrganization) { + await tx.user.update({ + where: { + id: user.id, + }, + data: { + organizationId: team.id, + }, + }); + } - const membership = await prisma.membership.update({ - where: { - userId_teamId: { userId: user.id, teamId: team.id }, - }, - data: { - accepted: true, - }, + const membership = await tx.membership.update({ + where: { + userId_teamId: { userId: user.id, teamId: team.id }, + }, + data: { + accepted: true, + }, + }); + return membership; }); + closeComUpsertTeamUser(team, user, membership.role); // Accept any child team invites for orgs.