From 3ac0eb212847afb09b7cccff0d289e30919649f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C5=A0mahel?= <48548230+ceskyDJ@users.noreply.github.com> Date: Sat, 7 Jun 2025 21:44:04 +0200 Subject: [PATCH] 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. --- client/src/Pages/Auth/Login/Components/EmailStep.jsx | 1 - client/src/Validation/validation.js | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/client/src/Pages/Auth/Login/Components/EmailStep.jsx b/client/src/Pages/Auth/Login/Components/EmailStep.jsx index 45babead1..20e8d6bfb 100644 --- a/client/src/Pages/Auth/Login/Components/EmailStep.jsx +++ b/client/src/Pages/Auth/Login/Components/EmailStep.jsx @@ -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) : ""} diff --git a/client/src/Validation/validation.js b/client/src/Validation/validation.js index d94f7c49a..b79d4c824 100644 --- a/client/src/Validation/validation.js +++ b/client/src/Validation/validation.js @@ -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",