简体   繁体   中英

Saving a Parse User using Parse Cloud

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.

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);
          }
        });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM