Hugues BR
Hugues BR

Reputation: 2258

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

Upvotes: 1

Views: 199

Answers (2)

Fosco
Fosco

Reputation: 38506

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

response.success(object);

Upvotes: 1

Mo Nazemi
Mo Nazemi

Reputation: 2717

Change your code to use isNew() method:

Parse.Cloud.beforeSave(Parse.User, function(request, response) {
  console.log('Ran beforeSave on a User');

  if(!request.object.isNew()) {
    response.success(); 
  } else {
    console.log('new user!');
    request.object.set('aaa', 'xxx');
    response.success();
  }
});

Upvotes: 0

Related Questions