Fix for inviteUserToOrganization for usernames with no email formats

This commit is contained in:
carlosmonastyrski
2025-06-05 20:47:29 -03:00
parent ce170a6a47
commit 635f027752
2 changed files with 21 additions and 11 deletions
+16 -10
View File
@@ -835,16 +835,22 @@ export const orgServiceFactory = ({
// if the user doesn't exist we create the user with the email
if (!inviteeUser) {
inviteeUser = await userDAL.create(
{
isAccepted: false,
email: inviteeEmail,
username: inviteeEmail,
authMethods: [AuthMethod.EMAIL],
isGhost: false
},
tx
);
// TODO(carlos): will be removed once the function receives usernames instead of emails
const usersByEmail = await userDAL.findUserByEmail(inviteeEmail, tx);
if (usersByEmail?.length === 1) {
[inviteeUser] = usersByEmail;
} else {
inviteeUser = await userDAL.create(
{
isAccepted: false,
email: inviteeEmail,
username: inviteeEmail,
authMethods: [AuthMethod.EMAIL],
isGhost: false
},
tx
);
}
}
const inviteeUserId = inviteeUser?.id;