title: Firebase Permission denied (read and write) with Authentication
body: <p>I want to read and write in my database with authentication but I got a <code>Permission denied</code> for both. I'm trying to figure out why it's not working. </p>
  
  <p>I used the default rules since I want authentication, as explained in the doc.</p>
  
  <blockquote>
    <p>The default rules require Authentication. They allow full read and write > access to authenticated users of your app. They are useful if you want data open > to all users of your app but don't want it open to the world.</p>
  </blockquote>
  
  <ul>
  <li><p><strong>Firebase rules :</strong></p>
  
  <pre><code>{
    "rules": {
      ".read": "auth != null",
      ".write": "auth != null"
    }
  }
  </code></pre></li>
  <li><p><strong>Create user :</strong></p>
  
  <pre><code>   auth.createUserWithEmailAndPassword(email, password)
          .addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                  Log.d("USER_CREATE", "createUserWithEmail:onComplete:" + task.isSuccessful());
  
                  // If sign in fails, display a message to the user. If sign in succeeds
                  // the auth state listener will be notified and logic to handle the
                  // signed in user can be handled in the listener.
                  if (!task.isSuccessful()) {
                      Toast.makeText(getApplicationContext(), "Authentication failed.",
                              Toast.LENGTH_SHORT).show();
                  } else {
                      startActivity(new Intent(SignupActivity.this, MainActivity.class));
                      finish();
                  }
  
                  // ...
              }
          });
  </code></pre></li>
  <li><p><strong>Sign in user :</strong></p>
  
  <pre><code>auth.signInWithEmailAndPassword(email, password)
          .addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                  Log.d("COMPLETE", "signInWithEmail:onComplete:" + task.isSuccessful());
              }
          });
  </code></pre></li>
  </ul>
  
  <p>I got an <code>AuthListener</code>and it logs me that the user is signed in.</p>
  
  <ul>
  <li><p><strong>AuthListener :</strong></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></li>
  <li><p><strong>Read test :</strong> (with a node I manually added in the database) </p>
  
  <pre><code>firebase.child("test").addValueEventListener(new ValueEventListener() {
  
      @Override
      public void onDataChange(DataSnapshot snapshot) {
          Log.d("result", snapshot.getValue()+"");
      }
  
      @Override
      public void onCancelled(FirebaseError error) {
          Log.d("The read failed: ", error.getMessage());
      }
  });
  </code></pre></li>
  <li><p><strong>Write test</strong> : I want a main node <code>users</code>with two categories of users : <code>devs</code>and <code>employers</code>.</p>
  
  <pre><code>Firebase usersRef  = firebase.child("users").child("devs");
      FirebaseUser user = auth.getCurrentUser();
  
  Map&lt;String, String&gt; userMap = new HashMap&lt;String, String&gt;();
  userMap.put("name", "blabla");
  userMap.put("city", "Brussels");
  
  Map&lt;String, Map&lt;String, String&gt;&gt; users = new HashMap&lt;String, Map&lt;String, String&gt;&gt;();
  users.put(user.getUid().toString(), userMap);
  usersRef.setValue(users);
  </code></pre></li>
  <li><p><strong>Logs :</strong></p>
  
  <pre><code>D/AUTH LISTENER: onAuthStateChanged:signed_in:wnomkwiOWOb4wNNLSsrWeT5xxUq1
  D/USER_CREATE: createUserWithEmail:onComplete:true
  I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
  D/ACTION BAR?: android.support.v7.app.ToolbarActionBar@36c3cd2a
  W/SyncTree: Listen at /test failed: FirebaseError: Permission denied
  D/The read failed:: Permission denied
  D/FirebaseAuth: Notifying listeners about user ( wnomkwiOWOb4wNNLSsrWeT5xxUq1 ).
  D/FirebaseAuth: Notifying listeners about user ( wnomkwiOWOb4wNNLSsrWeT5xxUq1 ).
  D/FirebaseApp: Notifying auth state listeners.
  D/FirebaseApp: Notified 0 auth state listeners.
  D/AUTH LISTENER: onAuthStateChanged:signed_in:wnomkwiOWOb4wNNLSsrWeT5xxUq1
  D/FirebaseApp: Notifying auth state listeners.
  D/FirebaseApp: Notified 0 auth state listeners.
  D/AUTH LISTENER: onAuthStateChanged:signed_in:wnomkwiOWOb4wNNLSsrWeT5xxUq1
  D/COMPLETE: signInWithEmail:onComplete:true
  </code></pre></li>
  </ul>
  
  <p>I made those 2 tests with public permission (write : true, read : true) and it was working, so something must be wrong with my authentication. I'm probably misunderstanding/missing something but don't really see what exactly. Would be very nice If someone would like to enlighten me!</p>