refactor: Simplify client-side email validation

We don't need to implement custom check for lowercase, as it's
been already implemented in joi library. Also we don't need to
convert email to lowercase twice (via onChange and onInput event
handlers), onChange is completely sufficient and as it's just
before form validation, it's the better one.
This commit is contained in:
Michal Šmahel committed 2025-06-09 21:54:47 +02:00
1 parent c5efa71875
commit 3ac0eb2128
2 files changed
+1 -8

No files matched your search

@@ -55,7 +55,6 @@ const EmailStep = ({ form, errors, onSubmit, onChange }) => {
placeholder="jordan.ellis@domain.com"
autoComplete="email"
value={form.email}
onInput={(e) => (e.target.value = e.target.value.toLowerCase())}
onChange={onChange}
error={errors.email ? true : false}
helperText={errors.email ? t(errors.email) : ""}
+1 -7
View File
@@ -71,13 +71,7 @@ const credentials = joi.object({
.string()
.trim()
.email({ tlds: { allow: false } })
.custom((value, helpers) => {
const lowercasedValue = value.toLowerCase();
if (value !== lowercasedValue) {
return helpers.message("Email must be in lowercase");
}
return lowercasedValue;
})
.lowercase()
.messages({
"string.empty": "authRegisterEmailRequired",
"string.email": "authRegisterEmailInvalid",