Skip to content

Commit

Permalink
Clean authData of null values on _User update
Browse files Browse the repository at this point in the history
Adds a step to the RestWrite#execute chain: it cleans the response
authData object of null values.

For example, this:

{"authData": {"anonymous": null}, "updatedAt", ...}

will be transformed to this:

{"updatedAt", ...}

And this:

{"authData": {"anonymous": null, "twitter": ...}, "updatedAt", ...}

will be transformed to this:

{"authData": {"twitter": ...}, "updatedAt", ...}

Fixing this issue will fix anonymous user upgrades from the Android SDK.
  • Loading branch information
yuzeh committed Mar 29, 2016
1 parent 337d3c2 commit 603b427
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ RestWrite.prototype.execute = function() {
return this.expandFilesForExistingObjects();
}).then(() => {
return this.runDatabaseOperation();
}).then(() => {
return this.cleanUserAuthData();
}).then(() => {
return this.handleFollowup();
}).then(() => {
Expand Down Expand Up @@ -824,5 +826,21 @@ RestWrite.prototype.sanitizedData = function() {
return Parse._decode(undefined, data);
}

RestWrite.prototype.cleanUserAuthData = function() {
if (this.response && this.response.response && this.className === '_User') {
let user = this.response.response;
if (user.authData) {
Object.keys(user.authData).forEach((provider) => {
if (user.authData[provider] === null) {
delete user.authData[provider];
}
});
if (Object.keys(user.authData).length == 0) {
delete user.authData;
}
}
}
};

export default RestWrite;
module.exports = RestWrite;

0 comments on commit 603b427

Please sign in to comment.