Search code examples
herokuparse-platformparse-cloud-code

Setting some Parse.User property on beforeSave when running on Heroku


Can you edit data in beforeSave callback and if yes, how?

Looking at various docs, it seem like this code should work (using "_User" or Parse.User) and I can see Ran beforeSave on a User and new user! in my logs but the key aaa is still empty..

I've tried to add user.save() after user.set but still no luck. Any idea?

Parse.Cloud.beforeSave("_User", function(request, response) {
  console.log('Ran beforeSave on a User');
  var user = request.object;
  if(user.existed()) {
    response.success(); 
  } else {
    console.log('new user!');
    user.set('aaa', 'xxx');
    response.success();
  }
});

EDIT 2015/12/03: Maybe critical info, this code is running on heroku. http://blog.parse.com/announcements/introducing-heroku-parse/

EDIT 2015/12/05: It seem to be a bug with Heroku / Parse integration. beforeSave hook are called but doesn't seem to allow you to edit the request.object..

EDIT 2015/12/07: I've created an issue on the CloudCode-Express repo https://github.com/ParsePlatform/CloudCode-Express/issues/6


Solution

  • Using Webhooks, you need to pass back the changed object:

    response.success(object);