Reputation: 553
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.
Upvotes: 1
Views: 6863
Reputation: 71
You just need to pass options inside normalizeEmail ()
in your validation chain, in a middleware:
normalizeEmail({ gmail_remove_dots: false })
Upvotes: 7
Reputation: 553
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.
Upvotes: 0
Reputation: 12
You cannot remove any . or _
since it's part of the user's e-mail.
Here and example of validating an email address
Upvotes: -1