sequelize.js custom validator, check for unique username / password

后端 未结 4 731
野趣味
野趣味 2021-02-02 03:47

Imagine I have defined the following custom validator function:

isUnique: function () { // This works as expected
  throw new Error({error:[{message:\'Email addr         


        
4条回答
  •  野性不改
    2021-02-02 04:20

    You can verify if the email already exists like that:

    email: {
      type: Sequelize.STRING,
      allowNull: false,
      validate: {
        isEmail:true
      },
      unique: {
          args: true,
          msg: 'Email address already in use!'
      }
    }
    

提交回复
热议问题