简体   繁体   中英

Cloud Code Not Updating User's Username Properly

For some reason Cloud Code isn't updating the current user's username, even though it is updating the email field. I'm using the master key, and although everything returns success, the username doesn't update (even on the data browser).

Here's my code:

        //Get Current User
        var user = Parse.User.current();

        //Update username
        user.set("email", request.params.email);
        user.set("username", request.params.username);
        user.save(null, {

                      //Success
                      success: function(user) {

                        //Done
                        response.success("Username saved! 🎉");
                      },

                      //Error
                      error: function(user, error) {

                        // Execute any logic that should take place if the save fails.
                        response.error("Aww man. Something went wrong. Please try again. 😅");
                      }

        });

I've made sure that the parameters are being passed correctly, and that there isn't a mistake with the name etc on my iOS app.

My guess is that there is an issue with getting the calling user.

Use request.user to get the calling user and try the following.

// Get the requesting user
var user = request.user;

if (user) {
    user.set("email", request.params.email);
    user.set("username", request.params.username);
    user.save(null, {
        success: function(user) {
            response.success("Username saved! 🎉");
        },
        error: function(error) {
            alert("Error: " + error.code + " " + error.message);
        }
    });
} else {
    response.error("Aww man. Something went wrong. Please try again. 😅");
}

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