在Sails Mongo blocks之前将密码字段设置为'required'

时间:2017-07-06 09:24:09

标签: node.js sails.js waterline bcrypt sails-mongo

我的API使用SailsJs和MongoDb。对于用户创建,我使用mount运行bcrypt来哈希我的密码字段。

我遇到了这个奇怪的错误,其中如果我将我的encrPassword字段设置为

beforeCreate lifecycle callback

我的代码停止工作并发出以下错误:

{required : true}

这是我的代码示例:

 {
  "error": "E_VALIDATION",
  "status": 400,
  "summary": "1 attribute is invalid",
  "model": "User",
  "invalidAttributes": {
    "encrPassword": [
      {
        "rule": "string",
        "message": "Value should be a string (instead of null, which is an object)"
      },
      {
        "rule": "required",
        "message": "\"required\" validation rule failed for input: null\nSpecifically, it threw an error.  Details:\n undefined"
      }
    ]
  }

PS。我严格检查了错别字;上面示例中的任何拼写错误或语法错误都是编辑隐藏任何我不想共享的代码的结果

1 个答案:

答案 0 :(得分:1)

在致电beforeCreate之前完成验证 那时没有encrPassword因此错误。