Skip to content

[CAL-3055] 500 when inviting a team member and there's a conflict in the generated username #13464

@zomars

Description

@zomars

The bug comes from here:

const usernameOrEmail = usernamesOrEmails[index];
const { orgId, autoAccept } = connectionInfoMap[usernameOrEmail];
const [emailUser, emailDomain] = usernameOrEmail.split("@");
const username =
emailDomain === autoAcceptEmailDomain
? slugify(emailUser)
: slugify(`${emailUser}-${emailDomain.split(".")[0]}`);
const createdUser = await tx.user.create({
data: {
username,
email: usernameOrEmail,
verified: true,
invitedTo: input.teamId,
organizationId: orgId || null, // If the user is invited to a child team, they are automatically added to the parent org
teams: {
create: {
teamId: input.teamId,
role: input.role as MembershipRole,
accepted: autoAccept, // If the user is invited to a child team, they are automatically accepted
},
},
},
});

This is causing a weird edge case where there might be the possibility that the generated user may exist already. causing a prisma error. Example: we have robert@example.com being converted to robert-example username. Which already exists in prod. On production this only returns a 500 error:

On dev we get this:

Object { message: "Invalid `prisma.user.create()` invocation: Unique constraint failed on the fields: (`username,`)", code: -32603, data: {…} }

Originally posted by @zomars in #11238 (comment)

From SyncLinear.com | CAL-3055

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions