diff --git a/pages/api/auth/signup.ts b/pages/api/auth/signup.ts index 5c92ddf1d1..ed43e98e95 100644 --- a/pages/api/auth/signup.ts +++ b/pages/api/auth/signup.ts @@ -53,7 +53,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const hashedPassword = await hashPassword(password); - await prisma.user.upsert({ + const user = await prisma.user.upsert({ where: { email: userEmail }, update: { username, @@ -69,5 +69,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) }, }); + // If user has been invitedTo a team, we accept the membership + if (user.invitedTo) { + await prisma.membership.update({ + where: { + userId_teamId: { userId: user.id, teamId: user.invitedTo }, + }, + data: { + accepted: true, + }, + }); + } + res.status(201).json({ message: "Created user" }); } diff --git a/playwright/auth/auth-index.test.ts b/playwright/auth/auth-index.test.ts index 674a1d2970..6bcb61aac6 100644 --- a/playwright/auth/auth-index.test.ts +++ b/playwright/auth/auth-index.test.ts @@ -94,11 +94,25 @@ test.describe("Can signup from a team invite", async () => { const createdUser = await prisma.user.findUnique({ where: { email: testUser.email }, + include: { + teams: { + include: { + team: true, + }, + }, + }, }); + // Check that the user was created expect(createdUser).not.toBeNull(); expect(createdUser?.username).toBe(testUser.validUsername); expect(createdUser?.password).not.toBeNull(); expect(createdUser?.emailVerified).not.toBeNull(); + // Check that the user accepted the team invite + expect(createdUser?.teams).toHaveLength(1); + expect(createdUser?.teams[0].team.name).toBe(team.name); + expect(createdUser?.teams[0].team.slug).toBe(team.slug); + expect(createdUser?.teams[0].role).toBe("MEMBER"); + expect(createdUser?.teams[0].accepted).toBe(true); }); });