Search code examples
angularjsputloopbackjsstrongloop

StrongLoop: Update currentUser without putting the password?


Setting:

  • Strongloop / loopback: ^2.10.2
  • AngularJS 1.3

Problem:

On the profile page the user model gets updated, but the password should not be transferred (anyway it is hashed and not available.).

Approach:

So I tried the following.

user.$save().then(cb);

the user-object is a $ressouce and it does create a PUT /users/?id=1 request to the server, but strongloop tries to INSERT the entity instead of updating, and the error pops up:

"message":"ER_NO_DEFAULT_FOR_FIELD: Field 'password' doesn't have a default value"

Question:

How can I tell strongloop to make an update in the PUT and not an insert?

Thank you!


Solution

  • A workaround was provided here.

    So in your code replace the call to user.$save by the following

    userData = {'someCustomUserProperty':'someValue'};
    User.prototype$updateAttributes({ id: user.id }, userData);