Skip to content

Commit

Permalink
fix: move check inside lock
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Jul 25, 2020
1 parent af91c26 commit 5713576
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/user/create.js
Expand Up @@ -15,13 +15,14 @@ module.exports = function (User) {
data.email = String(data.email).trim();
}

await User.isDataValid(data);

try {
await lock(data.username, '[[error:username-taken]]');
if (data.email) {
await lock(data.email, '[[error:email-taken]]');
}

await User.isDataValid(data);

return await create(data);
} finally {
await db.deleteObjectFields('locks', [data.username, data.email]);
Expand Down

0 comments on commit 5713576

Please sign in to comment.