I have migrated my Parse app to Heroku as per the migration guide on the Parse blog. Things seem to work fine except running a query 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 used to run fine when hosted on Parse. But after migrating I'm getting the above error. Other cloud code that does not use ParseQuery still work fine.
Any ideas on what the problem could be?
UPDATE
Still not able to find a fix for this 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:
[ ParseError { code: undefined, message: 'unauthorized' }, ParseError { code: undefined, message: 'unauthorized' } ]
Parse.Cloud.userMasterKey();
, there are no errors, but wont execute anything in the success block either i.e. log "This line was executed!". I can confirm that logging itself is working because other console.log(...)
statements work.Just FYI: Item
is a Parse class with columns assignee
and prevAssignee
being columns that are pointers to _User
s.
Any help is much appreciated.
query.get(prevAssigneeId, {
useMasterKey: true
success: function(prevAssignee) {
console.log("Fetch prevAssignee: Success");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With