The request parameter in the cloud code does not work after switching to Heroku

I migrated the Parse app to Heroku according to the migration guide on the Parse blog. Everything seems to work just fine, except doing the request in my cloud code. Here is my code:

Parse.Cloud.afterSave("Item", function(request) { //Parse.Cloud.useMasterKey(); //Uncomenting this line yields the same error var query = new Parse.Query(Parse.User); var prevAssigneeId = request.object.get("prevAssignee").id; var assigneeId = request.object.get("assignee").id; query.get(prevAssigneeId, { // <-- Results in an error success: function(prevAssignee) { console.log("Fetch prevAssignee: Success"); query.get(assigneeId, { success: function(assignee) { console.log("Fetch assignee: Success"); // Do something with the fetched users! }, error: function(object, error) { console.log("Query for assignee: "); console.log(error); } }); }, error: function(object, error) { console.log("Query for prevAssignee: "); console.log(error); //<-- Error is logged here } }); }); 

Error

ParseError { code: undefined, message: 'unauthorized' }

This cloud code is used to work correctly when placed in Parse. But after the migration, I get the above error. Another cloud code that does not use ParseQuery still works fine.

Any ideas on what could be the issue?

UPDATE

The fix could not be found, so I tried changing the code to the following:

 Parse.Cloud.afterSave("Item", function(request) { console.log("Executing afterSave"); function findUser(user_id) { var query = new Parse.Query(Parse.User); //Parse.Cloud.userMasterKey(); return query.get(user_id); } var prevAssigneePromise = findUser(request.object.get("prevAssignee").id); var assigneePromise = findUser(request.object.get("assignee").id); var promises = [prevAssigneePromise, assigneePromise]; Parse.Promise.when(promises).then(function(prevAssignee, assignee) { //Do something here! console.log("This line was executed!"); }, function(error) { console.log(error); }); }); 

Now I noticed the following behavior:

  • Execute as is, it produces the same error: [ ParseError { code: undefined, message: 'unauthorized' }, ParseError { code: undefined, message: 'unauthorized' } ]
  • If I uncomment Parse.Cloud.userMasterKey(); , there are no errors, but will not do anything in the success block, that is, log "This line has been executed!". I can confirm that the log itself works because other console.log(...) statements work.

Just FYI: Item is a Parse class with assignee and prevAssignee columns that are pointers to _User s.

Any help is greatly appreciated.

+5
source share
1 answer
 query.get(prevAssigneeId, { useMasterKey: true success: function(prevAssignee) { console.log("Fetch prevAssignee: Success"); } } 
+1
source

Source: https://habr.com/ru/post/1242840/


All Articles