2
votes

I have a Cloud Code function that is being called by users. In that function, I create a new object, "Invitation", which triggers a before_save handler when saving.

Since a user is running the Cloud Code function, I would expect request.user in the before_save function to be the same, but it appears to be saving the Invitation object as master, resulting in request.user being null.

Parse.Cloud.define("sendInvite", function(request, response) {
  var invitation = new Invitation();
  invitation.save().then(function(invitation){
    response.success();
  }, function(error){
    response.error(error);
  });
});

Parse.Cloud.beforeSave("Invitation", function(request, response) {

  var sender = request.user;
  // sender is null, since master key is being used...

});

This doesn't seem like correct behaviour – the cloud code function shouldn't default to executing using the master key unless explicitly told to do so.

Any thoughts?

2

2 Answers

1
votes

The issue was that Parse.Cloud.useMasterKey() was used outside of a function in one of our requires for Parse Hosting (require(cloud/app.js)).

0
votes

The two cases when CloudCode uses the master key are when the CloudCode calls Parse.Cloud.useMasterKey() or when the CloudCode was invoked by a caller which uses the master key. Check whether sendInvites is being called from an environment which uses the master key.