better erorr message when username contains profanity

This commit is contained in:
Miodec 2022-11-08 12:54:23 +01:00
parent 0f589b0e5b
commit 682216588d

View file

@ -68,13 +68,21 @@ const usernameValidation = joi
.string()
.required()
.custom((value, helpers) => {
return isUsernameValid(value)
? value
: helpers.error("string.pattern.base");
if (containsProfanity(value)) {
return helpers.error("string.profanity");
}
if (!isUsernameValid(value)) {
return helpers.error("string.pattern.base");
}
return value;
})
.messages({
"string.profanity":
"The username contains profanity. If you believe this is a mistake, please contact us ",
"string.pattern.base":
"Username invalid. Name cannot use special characters or contain more than 16 characters. Can include _ . and -",
"Username invalid. Name cannot use special characters or contain more than 16 characters. Can include _ . and - ",
});
const languageSchema = joi.string().min(1).required();