1

I'm trying to use Parse Cloud to save some changes to the current logged in user, but for some reason it results in response.error().

I have reduced my code to this snippet just for testing purposes.

Parse.Cloud.define("createGroup", function(request, response) {
 var currentUser = Parse.User.current();
 currentUser.set("currentGroupId", "test");
 currentUser.save(null, {
          success: function(currentUser){
            response.success();
          },
          error: function(error){
            response.error("error " + error);
          }
        });
});

The error log message says error [object Object]. I really have no idea what is wrong with my code, I'd appreciate any help.

1 Answer 1

1

You need to place

Parse.Cloud.useMasterKey();

in your main.js to gain access to the Users table or the Installations table. If it doesn't work when called inside the function, you may have to call it outside of any function definitions

Parse.Cloud.define("createGroup", function(request, response) {
    Parse.Cloud.useMasterKey();
    var currentUser = Parse.User.current();
    console.log(JSON.stringify(currentUser)); //make sure you are getting something here
    currentUser.set("currentGroupId", "test");
    currentUser.save(null, {
          success: function(currentUser){
            response.success();
          },
          error: function(error){
            response.error("error " + error);
          }
        });
});
Sign up to request clarification or add additional context in comments.

2 Comments

I have tried using the masterkey but the error is still there. The console log is displaying the correct json object. I even removed the currentUser.set("currentGroupId", "test"); but for some reason it will never save() successfully. Any ideas?
I solved the problem. Turns out I had a beforeSave() function that was causing the error. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.