I am following this awesome tutorial in learning how to do a signup/login feature in Node.js and React.js. I am trying to implement a confirmation password feature where a user needs to enter their password a second time when signing up. I already created a field to confirm the password in React.js. When I tried to implement and test it, I got a "Password does not match" even though I typed in the correct password. I am not sure what went wrong. Here is the code that I am working on with the password confirmation feature:
function validateSignupForm(payload) {
const errors = {};
let isFormValid = true;
let message = '';
if (!payload || typeof payload.email !== 'string' || !validator.isEmail(payload.email)) {
isFormValid = false;
errors.email = 'Please provide a correct email address.';
}
if (!payload || typeof payload.password !== 'string' || payload.password.trim().length < 8) {
isFormValid = false;
errors.password = 'Password must have at least 8 characters.';
}
//Trying to confirm password
if (!payload || payload.password !== payload.password2) {
isFormValid = false;
errors.password2 = 'Password does not match.';
}
if (!payload || typeof payload.name !== 'string' || payload.name.trim().length === 0) {
isFormValid = false;
errors.name = 'Please provide your name.';
}
if (!isFormValid) {
message = 'Check the form for errors.';
}
return {
success: isFormValid,
message,
errors
};
}
I attempted to add another if
statement to see if that will work, but it did not and not sure what to do. Also, if it is not too much trouble, I would like to hash that confirmed password too.
via emvo
No comments:
Post a Comment