title: Firebase Auth authStateChanges trigger
body: <p>I'm using firebase to authenticate a user and create a user in firestore database :</p>
  <pre class="lang-dart prettyprint-override"><code>final auth.FirebaseAuth _firebaseAuth;
  
  Future&lt;void&gt; signUp(
        {@required String email, @required String password}) async {
      assert(email != null &amp;&amp; password != null);
      try {
        await _firebaseAuth.createUserWithEmailAndPassword(
            email: email, password: password);
        await createUserInDatabaseIfNew();
        
      } on Exception {
        throw SignUpFailure();
      }
    }
  </code></pre>
  <p>With firebase, once the method <code>.createUserWithEmailAndPassword()</code> is executed, it triggers right after the <code>authStateChanges</code> which I am using in my code to send the new user in the <code>user</code> stream, and eventually retrieve its data from the database</p>
  <pre class="lang-dart prettyprint-override"><code>Stream&lt;User&gt; get user {
      return _firebaseAuth.authStateChanges().map((firebaseUser) {
        return firebaseUser == null ? User.empty : firebaseUser.toUser;
      });
    }
  </code></pre>
  <pre class="lang-dart prettyprint-override"><code>StreamSubscription&lt;User&gt; _userSubscription = _authenticationRepository.user.listen((user) {
            return add(AuthenticationUserChanged(user));}
  </code></pre>
  <pre class="lang-dart prettyprint-override"><code>if(event is AuthenticationUserChanged){
        if(event.user != User.empty){
          yield AuthenticationState.fetchingUser();
          User userFromDatabase;
          try{
            var documentSnapshot = await _firebaseUserRepository.getUser(event.user.id);
            userFromDatabase = User.fromEntity(UserEntity.fromSnapshot(documentSnapshot));
            yield AuthenticationState.authenticated(userFromDatabase); 
            
          }
  </code></pre>
  <p>The problem that I am facing, is that because of <code>_firebaseAuth.createUserWithEmailAndPassword</code>, <code>_firebaseAuth.authStateChanges</code> is triggerd <em>before</em> the user is created in the database, and eventually when I try to retrieve that user, it still does not exist in the database.</p>
  <p>I would like <code>_firebaseAuth.authStateChanges()</code> to be triggered <em>after</em> my method <code>createUserInDatabaseIfNew</code> runs.</p>
  <p>How could I achieve that ?</p>