I was working with express-validator
when i encountered that i used normalize email for validation of email while signing up so i stored the normalized email to server.
Validation code:
router.post(
"/signup",
[
check("name").not().isEmpty(),
check("email").normalizeEmail().isEmail(),
check("password").isLength({ min: 6, max: 15 }),
],
userController.signupUser
);
Input email: [email protected]
normalized email: [email protected]
(storing in db)
Now the problem is when working on login the input email doesn't matches and shows invalid credentials.
I was working with express-validator
when i encountered that i used normalize email for validation of email while signing up so i stored the normalized email to server.
Validation code:
router.post(
"/signup",
[
check("name").not().isEmpty(),
check("email").normalizeEmail().isEmail(),
check("password").isLength({ min: 6, max: 15 }),
],
userController.signupUser
);
Input email: [email protected]
normalized email: [email protected]
(storing in db)
Now the problem is when working on login the input email doesn't matches and shows invalid credentials.
Share Improve this question edited Jun 27, 2020 at 20:30 Vivek Sharma asked Jun 26, 2020 at 22:49 Vivek SharmaVivek Sharma 5536 silver badges20 bronze badges3 Answers
Reset to default 7You just need to pass options inside normalizeEmail ()
in your validation chain, in a middleware:
normalizeEmail({ gmail_remove_dots: false })
After researching and observing I noticed that the code which was used at the time of signing up can be used to normalize email at the time of login, I just had to add:
router.post("/login",[check('email').normalizeEmail()], userController.loginUser);
After adding the email was converting to normalized one and can be used directly from requests.
You cannot remove any . or _
since it's part of the user's e-mail.
Here and example of validating an email address