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 @@ -431,6 +431,37 @@ describe('ParseUser', () => {
431
431
} ) ;
432
432
} ) ) ;
433
433
434
+ it ( 'removes the current user from disk when destroyed' , asyncHelper ( ( done ) => {
435
+ ParseUser . enableUnsafeCurrentUser ( ) ;
436
+ ParseUser . _clearCache ( ) ;
437
+ Storage . _clear ( ) ;
438
+ CoreManager . setRESTController ( {
439
+ request ( ) {
440
+ return ParsePromise . as ( {
441
+ objectId : 'uid9' ,
442
+ } , 201 ) ;
443
+ } ,
444
+ ajax ( ) { }
445
+ } ) ;
446
+
447
+ ParseUser . signUp ( 'destroyed' , 'password' ) . then ( ( u ) => {
448
+ expect ( u . isCurrent ( ) ) . toBe ( true ) ;
449
+ CoreManager . setRESTController ( {
450
+ request ( ) {
451
+ return ParsePromise . as ( { } , 200 ) ;
452
+ } ,
453
+ ajax ( ) { }
454
+ } ) ;
455
+ return u . destroy ( ) ;
456
+ } ) . then ( ( u ) => {
457
+ expect ( ParseUser . current ( ) ) . toBe ( null ) ;
458
+ return ParseUser . currentAsync ( ) ;
459
+ } ) . then ( ( current ) => {
460
+ expect ( current ) . toBe ( null ) ;
461
+ done ( ) ;
462
+ } ) ;
463
+ } ) ) ;
464
+
434
465
it ( 'updates the current user on disk when fetched' , asyncHelper ( ( done ) => {
435
466
ParseUser . enableUnsafeCurrentUser ( ) ;
436
467
ParseUser . _clearCache ( ) ;
You can’t perform that action at this time.
0 commit comments