Search code examples
node.jsvalidationemailexpress-validator

express-validator email normalization


I am using express-validator 6.9.2 for my Nodejs project. But when I used normalizeEmail() in my auth controller one of my test email "t.test@gmail.com" is stored in dB as "ttest@gmail.com". When I tried to log in to my app using t.test@gmail.com and ttest@gmail.com I was able to log in successfully. But when trying to create a new user with the email ttest@gmail.com. It shows an error email already exists. How can I normalize my email and store as "t.test@gmail.com" in dB?


Solution

  • In the options that you pass your validator you need to set property gmail_remove_dots to false. Here is the documentation.

    check('email').normalizeEmail({gmail_remove_dots:false})