Create new user with passwordHash column through connectors
Trying to use the mutation CreateUser with the input :
const input = {
username: 'Giannis',
password: 'mypassword',
email: "test@test.gr",
}
ctx.connectors.User.create(input, ctx)
i am getting that error :
error: password: is an invalid additional property message=password: is an invalid additional property, locations=[line=2, column=3], path=[createUser]
ValidationError: password: is an invalid additional property
that happens because connectors are using insertGraphAndFetch(filteredInput, options) which means that this validate's the input against the schema of User Model and User schema doesn't have a password field. Also the only way to set the passwordHash is through the save Function through password property of the User Model. check that :
that means that password should be set beforehand but this cannot happen if we using insertGraphAndFetch.
Suggestion
One Solution is to make use of $beforeInsert , $beforeUpdate in the User Model something like that :
$beforeInsert (context) {
return this.generateHash()
}
$beforeUpdate (queryOptions, context) {
return this.generateHash()
}
@jure i am more than happy to have a MR with the suggested solution or something that you think is better .