Skip to content

Commit 603b427

Browse files
committed
Clean authData of null values on _User update
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.
1 parent 337d3c2 commit 603b427

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/RestWrite.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ RestWrite.prototype.execute = function() {
7979
return this.expandFilesForExistingObjects();
8080
}).then(() => {
8181
return this.runDatabaseOperation();
82+
}).then(() => {
83+
return this.cleanUserAuthData();
8284
}).then(() => {
8385
return this.handleFollowup();
8486
}).then(() => {
@@ -824,5 +826,21 @@ RestWrite.prototype.sanitizedData = function() {
824826
return Parse._decode(undefined, data);
825827
}
826828

829+
RestWrite.prototype.cleanUserAuthData = function() {
830+
if (this.response && this.response.response && this.className === '_User') {
831+
let user = this.response.response;
832+
if (user.authData) {
833+
Object.keys(user.authData).forEach((provider) => {
834+
if (user.authData[provider] === null) {
835+
delete user.authData[provider];
836+
}
837+
});
838+
if (Object.keys(user.authData).length == 0) {
839+
delete user.authData;
840+
}
841+
}
842+
}
843+
};
844+
827845
export default RestWrite;
828846
module.exports = RestWrite;

0 commit comments

Comments
 (0)