File tree 2 files changed +23
-0
lines changed 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -277,6 +277,13 @@ export default class ParseUser extends ParseObject {
277
277
* @return {Boolean }
278
278
*/
279
279
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
+ }
280
287
this . set ( 'username' , username ) ;
281
288
}
282
289
Original file line number Diff line number Diff line change @@ -401,4 +401,20 @@ describe('ParseUser', () => {
401
401
done ( ) ;
402
402
} ) ;
403
403
} ) ) ;
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
+ } ) ;
404
420
} ) ;
You can’t perform that action at this time.
0 commit comments