i am a total begginer. I am trying to send a specific error message in password and password confirm validator in a mongoose schema.
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
password:{
type: String,
required: [true, 'Please provide a password.'],
minlength: 8
},
passwordConfirm:{
type: String,
required: [true, 'Please confirm your password.'],
validate:{
validator:
function (el) {
return el === this.password; //expectation
},
message: 'Password and password confirm was not the same' //something like this
}
},
});
when i test a user sign in request with different password and password confirm, i get the error message from my catch block in the router function, which is an overall error message that says that sth is wrong. But it could be anything. Isn’t there a simple way to just let the user know whats the issue like typed above? ‘Password and password confirm was not the same’ ?
Thank you
user25543263 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.