Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
sequelize.js custom validator for unique email to stop when user try to forgot password
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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!