Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 992
Jteve Sobs Avatar asked Oct 15 '25 04:10

Jteve Sobs


1 Answers

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.

like image 189
George Boateng Avatar answered Oct 16 '25 16:10

George Boateng