我的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。我严格检查了错别字;上面示例中的任何拼写错误或语法错误都是编辑隐藏任何我不想共享的代码的结果
答案 0 :(得分:1)
在致电beforeCreate
之前完成验证
那时没有encrPassword
因此错误。