I'm trying to update a Parse Server user from my client web app using the Javascript SDK.
I understand that this isn't possible using Parse.User but is possible using Parse.Object. I'm following the guidance to update Object but can't seem to get bast the 3rd line of the function.
function () {
var updateTheUser = Parse.Object.extend("_User");
var query = new Parse.User.current();
query.get(Parse.User.current().id, {
success: function (update) {
// The object was retrieved successfully.
update.set("phone", "01234 567890");
update.set("Barred", false);
update.save(null, {
success: function (update) {
console.log("Updated!");
}
});
},
error: function (object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
};
};
The only way that I've been able to solve this is by doing an AJAX request using the REST API
updateUser = function () {
var userId = Parse.User.current().id;
var data = JSON.stringify({
"username": username,
"firstname": firstname,
"lastname": lastname,
"email": email,
"phone": phone
});
$.ajax({
url: 'myServerURL' + userId,
type: 'PUT',
headers: {
'X-Parse-Application-Id': "my_api",
'X-Parse-Master-Key': "my_masterkey",
'Content-Type': "application/json"
},
"data": data,
success: function (result) {
// Do something with the result
alert("you have successfully updated your account. We're now going to need you to log back in with your new details?");
Parse.User.logOut();
window.location.href = "/#/login";
},
error: function (Response) {
alert(Response.error);
}
});
};
WARNING: As this contains the Master Key, it should be located in Cloud Code on your Parse Server, not in your web app