From 5b76e369e1be4dd87e97a45bb7d1c2d9faff6c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Mertel?= <10438157+jancimertel@users.noreply.github.com> Date: Sat, 20 Apr 2024 15:38:05 +0400 Subject: [PATCH] fix unique username/email --- packages/server/src/modules/users/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/server/src/modules/users/index.ts b/packages/server/src/modules/users/index.ts index c2ce7f127..781808a92 100644 --- a/packages/server/src/modules/users/index.ts +++ b/packages/server/src/modules/users/index.ts @@ -605,12 +605,18 @@ export default Router() await req.db.lock(); - if (data.email && (await User.findUserByLogin(req.db, data.email))) { - throw new UserNotUnique("email is in use"); + if (data.email) { + const existingEmail = await User.findUserByLogin(req.db, data.email); + if (existingEmail && existingEmail.id !== existingUser.id) { + throw new UserNotUnique("email is in use"); + } } - if (data.name && (await User.findUserByLogin(req.db, data.name))) { - throw new UserNotUnique("username is already used"); + if (data.name) { + const existingName = await User.findUserByLogin(req.db, data.name); + if (existingName && existingName.id !== existingUser.id) { + throw new UserNotUnique("username is already used"); + } } // email changed for non-verified user - regenerate hash & send activation email again