Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda