Reputation: 2543
I'm trying to run Parse cloud code for the first time from an AngularJS app. I keep getting the Parse.Error 'unauthorized' in my console.log. I've initialized Parse in my application and JS keys. Where am I going wrong?
Angular Code Format:
$scope.runSomething = function () {
Parse.Cloud.run('nameFunction', req.body, {
success: function (result){
},
error: function (error){
console.log(error);
}
})
I derive the req.body for the Parse.Cloud.run from prestanding info in the $scope.runSomething function.
My truncated main.js:
Parse.Cloud.define('nameFunction', function(request, response){
Parse.Cloud.useMasterKey();
//Do Stuff})
I'm sure I'm missing something small but I have no idea what.
Upvotes: 0
Views: 1282
Reputation: 62686
It sounds like you're close. Cloud functions (including before/after functions) must call success or error on the response object to properly complete, so...
Parse.Cloud.define('nameFunction', function(request, response){
Parse.Cloud.useMasterKey();
var someParam = request.params.someParam;
doSomePromiseReturningThing(someParam).then(function(result) {
response.success(result);
}, function (error) {
response.error(error);
});
});
Upvotes: 1