File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -419,6 +419,19 @@ export default class ParseUser extends ParseObject {
419
419
} ) ;
420
420
}
421
421
422
+ /**
423
+ * Wrap the default destroy behavior with functionality that logs out
424
+ * the current user when it is destroyed
425
+ */
426
+ destroy ( ...args : Array < any > ) : ParsePromise {
427
+ return super . destroy . apply ( this , args ) . then ( ( ) => {
428
+ if ( this . isCurrent ( ) ) {
429
+ return CoreManager . getUserController ( ) . removeUserFromDisk ( ) ;
430
+ }
431
+ return this ;
432
+ } ) ;
433
+ }
434
+
422
435
/**
423
436
* Wrap the default fetch behavior with functionality to save to local
424
437
* storage if this is current user.
@@ -750,6 +763,13 @@ var DefaultController = {
750
763
} ) ;
751
764
} ,
752
765
766
+ removeUserFromDisk ( ) {
767
+ let path = Storage . generatePath ( CURRENT_USER_KEY ) ;
768
+ currentUserCacheMatchesDisk = true ;
769
+ currentUserCache = null ;
770
+ return Storage . removeItemAsync ( path ) ;
771
+ } ,
772
+
753
773
setCurrentUser ( user ) {
754
774
currentUserCache = user ;
755
775
user . _cleanupAuthData ( ) ;
Original file line number Diff line number Diff line change @@ -453,6 +453,37 @@ describe('ParseUser', () => {
453
453
} ) ;
454
454
} ) ) ;
455
455
456
+ it ( 'removes the current user from disk when destroyed' , asyncHelper ( ( done ) => {
457
+ ParseUser . enableUnsafeCurrentUser ( ) ;
458
+ ParseUser . _clearCache ( ) ;
459
+ Storage . _clear ( ) ;
460
+ CoreManager . setRESTController ( {
461
+ request ( ) {
462
+ return ParsePromise . as ( {
463
+ objectId : 'uid9' ,
464
+ } , 201 ) ;
465
+ } ,
466
+ ajax ( ) { }
467
+ } ) ;
468
+
469
+ ParseUser . signUp ( 'destroyed' , 'password' ) . then ( ( u ) => {
470
+ expect ( u . isCurrent ( ) ) . toBe ( true ) ;
471
+ CoreManager . setRESTController ( {
472
+ request ( ) {
473
+ return ParsePromise . as ( { } , 200 ) ;
474
+ } ,
475
+ ajax ( ) { }
476
+ } ) ;
477
+ return u . destroy ( ) ;
478
+ } ) . then ( ( u ) => {
479
+ expect ( ParseUser . current ( ) ) . toBe ( null ) ;
480
+ return ParseUser . currentAsync ( ) ;
481
+ } ) . then ( ( current ) => {
482
+ expect ( current ) . toBe ( null ) ;
483
+ done ( ) ;
484
+ } ) ;
485
+ } ) ) ;
486
+
456
487
it ( 'updates the current user on disk when fetched' , asyncHelper ( ( done ) => {
457
488
ParseUser . enableUnsafeCurrentUser ( ) ;
458
489
ParseUser . _clearCache ( ) ;
You can’t perform that action at this time.
0 commit comments