@@ -55,6 +55,7 @@ import {
55
55
} from './watch_change' ;
56
56
import { ByteString } from '../util/byte_string' ;
57
57
import { isIndexedDbTransactionError } from '../local/simple_db' ;
58
+ import { User } from '../auth/user' ;
58
59
59
60
const LOG_TAG = 'RemoteStore' ;
60
61
@@ -756,13 +757,27 @@ export class RemoteStore implements TargetMetadataProvider {
756
757
await this . enableNetwork ( ) ;
757
758
}
758
759
759
- async handleCredentialChange ( ) : Promise < void > {
760
+ async handleCredentialChange ( user : User ) : Promise < void > {
761
+ this . asyncQueue . verifyOperationInProgress ( ) ;
762
+
760
763
if ( this . canUseNetwork ( ) ) {
761
- // Tear down and re-create our network streams. This will ensure we get a fresh auth token
762
- // for the new user and re-fill the write pipeline with new mutations from the LocalStore
763
- // (since mutations are per-user).
764
+ // Tear down and re-create our network streams. This will ensure we get a
765
+ // fresh auth token for the new user and re-fill the write pipeline with
766
+ // new mutations from the LocalStore (since mutations are per-user).
764
767
logDebug ( LOG_TAG , 'RemoteStore restarting streams for new credential' ) ;
765
- await this . restartNetwork ( ) ;
768
+
769
+ this . networkEnabled = false ;
770
+ await this . disableNetworkInternal ( ) ;
771
+ this . onlineStateTracker . set ( OnlineState . Unknown ) ;
772
+
773
+ await this . executeWithRecovery ( async ( ) => {
774
+ await this . syncEngine . handleUserChange ( user ) ;
775
+ this . networkEnabled = true ;
776
+ } ) ;
777
+ } else {
778
+ await this . executeWithRecovery ( ( ) =>
779
+ this . syncEngine . handleUserChange ( user )
780
+ ) ;
766
781
}
767
782
}
768
783
0 commit comments