mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
fix: better error message when creating a user with an existing email
fixes #1441
This commit is contained in:
@@ -81,6 +81,18 @@ router.post(
|
|||||||
const body = req.body;
|
const body = req.body;
|
||||||
const userRepository = getRepository(User);
|
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 passedExplicitPassword = body.password && body.password.length > 0;
|
||||||
const avatar = gravatarUrl(body.email, { default: 'mm', size: 200 });
|
const avatar = gravatarUrl(body.email, { default: 'mm', size: 200 });
|
||||||
|
|
||||||
|
@@ -62,6 +62,8 @@ const messages = defineMessages({
|
|||||||
validationpasswordminchars:
|
validationpasswordminchars:
|
||||||
'Password is too short; should be a minimum of 8 characters',
|
'Password is too short; should be a minimum of 8 characters',
|
||||||
usercreatedfailed: 'Something went wrong while creating the user.',
|
usercreatedfailed: 'Something went wrong while creating the user.',
|
||||||
|
usercreatedfailedexisting:
|
||||||
|
'Provided email is already in use by another user.',
|
||||||
usercreatedsuccess: 'User created successfully!',
|
usercreatedsuccess: 'User created successfully!',
|
||||||
email: 'Email Address',
|
email: 'Email Address',
|
||||||
password: 'Password',
|
password: 'Password',
|
||||||
@@ -305,10 +307,17 @@ const UserList: React.FC = () => {
|
|||||||
});
|
});
|
||||||
setCreateModal({ isOpen: false });
|
setCreateModal({ isOpen: false });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
addToast(intl.formatMessage(messages.usercreatedfailed), {
|
addToast(
|
||||||
appearance: 'error',
|
intl.formatMessage(
|
||||||
autoDismiss: true,
|
e.response.data.errors?.includes('USER_EXISTS')
|
||||||
});
|
? messages.usercreatedfailedexisting
|
||||||
|
: messages.usercreatedfailed
|
||||||
|
),
|
||||||
|
{
|
||||||
|
appearance: 'error',
|
||||||
|
autoDismiss: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
revalidate();
|
revalidate();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user