I get an "Parse::UserCannotBeAlteredWithoutSessionError" error using Parse in AngularJS when I use a copied user to modify data. The operations are done well, but the browser console shows the error. Here is the code related:
function createEmployeeCtrl($scope, $rootScope) {
$scope.loggedUser = Parse.User.current();
// Deep copy
var userCopy = jQuery.extend(true, {}, $scope.loggedUser);
// All data will be store in this object
$scope.formData = {};
var profileType = $scope.loggedUser.get("profileType");
$scope.usageRemainingLimit = $scope.loggedUser.get("usageRemaining");
// After process wizard
$scope.processForm = function() {
//INIT PARSE
var user = new Parse.User();
//... more code
var uso = 0;
var sessionToken = $scope.loggedUser._sessionToken; // I save current user token
user.signUp(null, {
success:function(user) {
Parse.User.become(sessionToken).then(function(user) {
Parse.User._saveCurrentUser(user);
}, function (error) {
alert("user not set");
});
userCopy.set("usageRemaining", $scope.usageRemainingLimit - uso);
userCopy.save();
//...window.location.href to a view of my app
},
error:function(user, error) {
console.log("ERROR!");
alert("Error: " + error.code + " " + error.message);
}
});
};
}