Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Delete unaccepted users upon merge user op

Tuan Dangcb9dabe03f0b
diff --git a/backend/src/services/user/user-dal.ts b/backend/src/services/user/user-dal.ts
index d0b03019f6..f2da0df0e2 100644
--- a/backend/src/services/user/user-dal.ts
+++ b/backend/src/services/user/user-dal.ts
@@ -94,14 +94,6 @@ export const userDALFactory = (db: TDbClient) => {
}
};
- const findMergeableUsers = async (email: string, tx?: Knex) => {
- const users = await (tx || db)(TableName.Users).where((builder) => {
- void builder.where({ email, isEmailVerified: true }).orWhere({ email, isAccepted: false });
- });
-
- return users;
- };
-
const updateUserEncryptionByUserId = async (userId: string, data: TUserEncryptionKeysUpdate, tx?: Knex) => {
try {
const [userEnc] = await (tx || db)(TableName.UserEncryptionKey)
@@ -162,7 +154,6 @@ export const userDALFactory = (db: TDbClient) => {
findUsersByProjectMembershipIds,
upsertUserEncryptionKey,
createUserEncryption,
- findMergeableUsers,
findOneUserAction,
createUserAction
};
diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.ts
index f04e0b35f5..693078fbdb 100644
--- a/backend/src/services/user/user-service.ts
+++ b/backend/src/services/user/user-service.ts
@@ -12,7 +12,6 @@ type TUserServiceFactoryDep = {
userDAL: Pick<
TUserDALFactory,
| "find"
- | "findMergeableUsers"
| "findOne"
| "findById"
| "transaction"
@@ -22,6 +21,7 @@ type TUserServiceFactoryDep = {
| "findOneUserAction"
| "createUserAction"
| "findUserEncKeyByUserId"
+ | "delete"
>;
userAliasDAL: Pick<TUserAliasDALFactory, "find" | "insertMany">;
orgMembershipDAL: Pick<TOrgMembershipDALFactory, "find" | "insertMany">;
@@ -86,8 +86,14 @@ export const userServiceFactory = ({
tx
);
- // check if there are users with the same email.
- const users = await userDAL.findMergeableUsers(email, tx);
+ // check if there are verified users with the same email.
+ const users = await userDAL.find(
+ {
+ email,
+ isEmailVerified: true
+ },
+ { tx }
+ );
if (users.length > 1) {
// merge users
@@ -129,6 +135,15 @@ export const userServiceFactory = ({
);
}
} else {
+ await userDAL.delete(
+ {
+ email,
+ isAccepted: false,
+ isEmailVerified: false
+ },
+ tx
+ );
+
// update current user's username to [email]
await userDAL.updateById(
user.id,