By Hemanta Sundaray on 2021-05-24
If you try to log in using the wrong email address or password or both, you would see an error message as shown below.
If you try to register for the second time using the same email address that you used to register the first time, you will receive an error message as shown below.
In addition to client-side validation, we are also doing server-side validation. In order to make sure that server-side validation is working as expected, we will temporarily comment out the highlighted code line as shown below in the RegisterForm.js file.
This means that we will not get any validation error messages even if we try to register using an invalid email address. However, we are checking for the validity of the email address server-side in the validate.js file. So, if I register using an invalid email address (hemanta@com for example) registrationValidation(req.body) will produce an error and the error message should be displayed on top of the form.
If you check the userRoutes.js file, you will see a highlighted line of code as shown below.
You will understand the above line of code when you console log the error object as shown below. The error message is available as the value of the message key. And the object the message key is part of is the first element of the details key, which is an array.
Go to part-13