title: Firebase 3 permission denied after first-time sign-in with Google, works after second time
body: <p>I have a Google sign-in implemented according to instructions:
  <a href="https://firebase.google.com/docs/auth/android/google-signin#authenticate_with_firebase" rel="nofollow">https://firebase.google.com/docs/auth/android/google-signin#authenticate_with_firebase</a> 
  Authentication and sign-in work fine, the user is authenticated and signed-in and the listener is called:</p>
  
  <pre><code>mAuthListener = new FirebaseAuth.AuthStateListener() {
          @Override
          public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
              FirebaseUser user = firebaseAuth.getCurrentUser();
              if (user != null) {
                  // User is signed in
                  Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
              } else {
                  // User is signed out
                  Log.d(TAG, "onAuthStateChanged:signed_out");
              }
          }
  </code></pre>
  
  <p>However, when trying to read from a user node/path having a standard security rule:</p>
  
  <pre><code>  "users": {
       "$user_id": {
         ".read": "auth !== null &amp;&amp; auth.uid === $user_id",
         ".write": "auth !== null"
       }
    }
  </code></pre>
  
  <p>with the following code triggered later manually:</p>
  
  <pre><code>DatabaseReference userRef = FirebaseDatabase.getInstance().getReference("users");
  userRef.child(uid).addListenerForSingleValueEvent(
          new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot data) {
                   ...
              }
              @Override
              public void onCancelled(DatabaseError error) {
                  Log.w(TAG, "fb sync onCancelled: " + error.getMessage());
              }
          });
  </code></pre>
  
  <p><code>onCancelled</code> is called with "permission denied". The <code>uid</code> is correct, equals to the user ID as returned by <code>firebaseAuth.getCurrentUser().getUid()</code></p>
  
  <p>Now the important part is that <strong>everything works fine if I sign-out and sign-in again, or if I terminate and re-launch the app</strong>. So I guess something must be wrong with the FirebaseAuth state after the initial sign-in, or maybe I miss something again..?</p>
  
  <p>Tested with <code>firebase-*:9.0.2</code> and <code>play-services-auth:9.0.2</code> as well as <code>9.2.0</code>.</p>