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) {
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.
source share