fix: better error message when creating a user with an existing email

fixes #1441
This commit is contained in:
sct
2021-04-18 19:53:55 +09:00
parent eb5d152886
commit f13f1c9451
2 changed files with 25 additions and 4 deletions

View File

@@ -81,6 +81,18 @@ router.post(
const body = req.body;
const userRepository = getRepository(User);
const existingUser = await userRepository.findOne({
where: { email: body.email },
});
if (existingUser) {
return next({
status: 409,
message: 'User already exists with submitted email.',
errors: ['USER_EXISTS'],
});
}
const passedExplicitPassword = body.password && body.password.length > 0;
const avatar = gravatarUrl(body.email, { default: 'mm', size: 200 });