Skip to content

Commit

Permalink
fix unique username/email
Browse files Browse the repository at this point in the history
  • Loading branch information
jancimertel committed Apr 20, 2024
1 parent dfc5729 commit 5b76e36
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/server/src/modules/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b76e36

Please sign in to comment.