Jteve Sobs
Jteve Sobs

Reputation: 244

Parse Cloud Code function Cannot use the Master Key, it has not been provided

I'm having some trouble in executing a function because I keep getting the same error concerning my masterKey not being provided:

[PFCloud callFunctionInBackground:@"changeUserModeratorStatus" withParameters:@{@"objectId": self.objId}];

The function:

Parse.Cloud.define("changeUserModeratorStatus", function(request, response) {
  Parse.Cloud.useMasterKey();
  var query = new Parse.Query(Parse.User);
  query.equalTo("objectId", request.params.objectId);
  query.first({
    success: function(anotherUser) {
      anotherUser.set("ModeratorStatus", "Approved");
      anotherUser.save(null, {
      success: function(anotherUser) {
        response.success("Successfully updated user.");
      },
    error: function(failedRetrieve, error) {
     response.error("Could not save changes to user.");
    }
   });
   },
   error: function(error) {
    response.error("Could not find user."); 
   }
  });
});

Edit, i've literally copy/pasted Hectors example on the forums, checked the documents and haven't found a solution. No matter what I do, I get an error : Cannot use the Master Key, it has not been provided

Upvotes: 4

Views: 2131

Answers (1)

George Boateng
George Boateng

Reputation: 66

You are probably missing the master key in the initialization of your cloud code -

 Parse.initialize(applicationId, javaScriptKey, masterKey).

Taking out the whole initialization fixed the problem for me since Parse actually initializes your cloud code with your application id, JavaScript key and master key so you don't have to do it.

Upvotes: 5

Related Questions