title: incomprehensible behavior during firebase and firestore update / authentication
body: <p>I'm creating an authentication code and updating of users role, everything goes well except during user updating, the session connects with the user that I have just modified. From my checks I find that right after updating the user it enters the ForEach. This problem does not occur when for example I refresh the page or the first time, it is when I switch from one session to another (signin) and I modify the user it changes session. I looked well I do not understand this behavior, if possible to give me help. Thank you in advance.</p>
  <p>here is my code :</p>
  <p>// USER DATA</p>
  <pre><code>  userDataChanges: BehaviorSubject&lt;any&gt; = new BehaviorSubject&lt;any&gt;(this.userData);
  
    setUserData(userData: any): void {
      this.userData = userData;
      this.userDataChanges.next(userData);
    }
  </code></pre>
  <p>// SIGNIN</p>
  <pre><code>  SignIn(email: string, password: string) {
  
      firebase.auth().signInWithEmailAndPassword(email, password)
  
        .then((user) =&gt; {
  
          this.firestore.collection(&quot;users&quot;).ref.where(&quot;uid&quot;, &quot;==&quot;, user.user.uid).onSnapshot(snap =&gt; {
            snap.forEach(userRef =&gt; {
  
              this.userData = userRef.data();
  
              //INIT USER
              this.SetUserData(this.userData);
  
              this.router.navigate(['postsignin']);
  
            })
  
          })
  
        }).catch(err =&gt; err)
    }
  </code></pre>
  <p>// UPDATE USER ROLE</p>
  <pre><code>  updateFirebaseUser(uid: string, role: string) {
      this.firestore.collection('users').doc(uid).update({ roles: role });
    }
  </code></pre>
  <p>// SIGNOUT</p>
  <pre><code>   SignOut() {
  
      firebase.auth().signOut().then(() =&gt; {
  
        localStorage.setItem('user', null);
        JSON.parse(localStorage.getItem('user'));
  
        this.ngZone.run(() =&gt; this.router.navigate([&quot;/sign-in&quot;]));
      })
    }
  </code></pre>