Parse Cloud Code: How to change authData column for user?

I am trying to implement the "Login with Facebook" feature in my application. I am using Parse as backend. The problem arises because Parse creates a new entry in the users table with authData and a random username, even if the same email address already exists in the user table. So now I ask the user to connect Facebook via the Facebook SDK and get their email. Then I call this cloud code from Android, which will look for the user associated with this email in the Parse User table. If the user exists, I am trying to update the authData field. It can update any column, but authData. It gives the following error when updating authData from cloud code.

Uncaught Tried to save an object with a pointer to a new, unsaved object

Below is the cloud code I am using:

Parse.Cloud.define("facebookLogin", function(request, response){
    Parse.Cloud.useMasterKey();
    var email = request.params.email;
    var userQuery = new Parse.Query(Parse.User);
    userQuery.equalTo("email", email);
    userQuery.first({
        success: function(user) {           
            if (user) {         
                Parse.Cloud.useMasterKey();
                var authData = util.createFBAuthData(request.params.id, request.params.access_token, request.params.expiration_date);
                console.log(authData);
                user.set("authData", authData);
                user.save(null, {
                    success: function(rest) {
                        response.success(rest);
                    },
                    error: function(error) {
                        console.log(error);
                        response.error(messageLog.getErrorMessage());
                    }
                }); 
            } else {

                createNewUserEntry(request);
            }
        }, 
        error: function() {
            response.error(messageLog.getErrorMessage());
        }
    });
})

      

I don't understand why Parse doesn't allow you to edit / update authData with cloud code. I can manually paste (Copy / Paste) json into the authData field in the users table from the analysis panel. Anyone who ran into this problem?

+3


source to share





All Articles