Skip to content

Commit da65b59

Browse files
committed
Merge pull request #47 from ParsePlatform/wangmengyan.strip_anonymous_user
Strip anonymous when we set username
2 parents da47720 + 2109a0a commit da65b59

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ParseUser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ export default class ParseUser extends ParseObject {
277277
* @return {Boolean}
278278
*/
279279
setUsername(username: string) {
280+
// Strip anonymity, even we do not support anonymous user in js SDK, we may
281+
// encounter anonymous user created by android/iOS in cloud code.
282+
var authData = this.get('authData');
283+
if (authData && authData.hasOwnProperty('anonymous')) {
284+
// We need to set anonymous to null instead of deleting it in order to remove it from Parse.
285+
authData.anonymous = null;
286+
}
280287
this.set('username', username);
281288
}
282289

src/__tests__/ParseUser-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,4 +401,20 @@ describe('ParseUser', () => {
401401
done();
402402
});
403403
}));
404+
405+
it('strip anonymity when we set username', () => {
406+
var user = new ParseUser();
407+
var authData = {
408+
anonymous : {
409+
id : 'anonymousId'
410+
}
411+
}
412+
user.set('authData', authData);
413+
expect(user.get('authData').anonymous.id).toBe('anonymousId');
414+
415+
// Set username should strip anonymous authData
416+
user.setUsername('test');
417+
expect(user.getUsername()).toBe('test');
418+
expect(user.get('authData').anonymous).toBe(null);
419+
});
404420
});

0 commit comments

Comments
 (0)