Getting validation error when trying to sign up new user to database. Not sure where to go from here
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const bcrypt = require('bcrypt');
const userSchema = new Schema({
firstName: {type: String, required: [true, 'cannot be empty']},
lastName: {type: String, required: [true, 'cannot be empty']},
email: { type: String, required: [true, 'cannot be empty'], unique: [true, 'this email address has been used'] },
password: { type: String, required: [true, 'cannot be empty'] },
}
);
//replace plaintext password
//pre middleware
userSchema.pre('save', function(next){
let user = this;
if (!user.isModified('password'))
return next();
bcrypt.hash(user.password, 10)
.then(hash => {
user.password = hash;
next();
})
.catch(err => next(error));
});
//comparison of password and hash
userSchema.methods.comparePassword = function(loginPassword) {
return bcrypt.compare(loginPassword, this.password);
}
module.exports = mongoose.model('User', userSchema);
Error : ValidationError: User validation failed: password: cannot be empty, email: cannot be empty, lastName: cannot be empty, firstName: cannot be empty at model.Document.invalidate (C:\Users\Dominick\Desktop\4166\Dominick Project 3\node_modules\mongoose\lib\document.js:2696:32) at C:\Users\Dominick\Desktop\4166\Dominick Project 3\node_modules\mongoose\lib\document.js:2516:17 at C:\Users\Dominick\Desktop\4166\Dominick Project 3\node_modules\mongoose\lib\schematype.js:1238:9 at processTicksAndRejections (internal/process/task_queues.js:77:11)