email: {
type: DataTypes.STRING,
allowNull: false,
validate: {
notNull: {
args: true,
msg: "Email is required"
},
notEmpty: {
args: true,
msg: "Email is required."
},
isEmail: {
args: true,
msg: "Email is not valid."
},
isUnique: function (value, next) {
var self = this;
User.findOne({where: {email: value}})
.then(function (user) {
// reject if a different user wants to use the same email
if (user && self.id !== user.id) {
return next('Email already exists!');
}
return next();
}).catch(function (err) {
return next(err);
});
}
}
}
its working good when user create but when try to forgot password it show email already exist i need to avoid isUnique on that time because then user email exists in database which is valid point but isUnique validation fail which not need to run that time .Any help please