title: Firebase database authentication with email & password
body: <p>i am new to firebase. i have set up a firebase realtime database and can read from and write to it if the read and write rules are set to true.</p>
  
  <p>i have a problem with authentication.i have set up authentication for google and email plus password. </p>
  
  <p>my goal is to allow any user to read the data but only one user (myself) can write data after logging in using a single email address and password.</p>
  
  <p>i can successfully read from and write to the database if i login with google (with rules set to: auth != null.) </p>
  
  <p>i can also read from and write to the database using the same rules (auth != null) if i log in with the email address and password.</p>
  
  <p>i don't know how to set it up to only allow write access for the single user logging in with an email address and password. </p>
  
  <p>i have tried including a user node in the rules but i can't get access when using the simulator (see below) and i don't know how to include the uid (which i can get after logging in) when building the reference - this is the reference i currently use (which works with the read and write rules set to true):</p>
  
  <pre><code>DatabaseReference databaseReference = mRootReference.child("Action_helper/1/Action_table_of_contents");
  </code></pre>
  
  <p>i have not included a users node in my database as i am assuming that is taken care of by firebase authentication.</p>
  
  <p>here is the layout of my data:</p>
  
  <p><a href="https://i.stack.imgur.com/hL6wq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hL6wq.png" alt="enter image description here"></a></p>
  
  <p>i have tried the simulator using various rules options. testing access using these settings in simulator (choosing the Custom provider option):</p>
  
  <p>Auth {"provider" : "firebase", "uid" : "Rp3OgoaABMN3hqTv0aF29ECQRCQ2"}</p>
  
  <p>note: i get the provider and uid from Firebase object after logging in with an email address and password which i have set up in Firebase authentication:</p>
  
  <pre><code>FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
      if (user != null) {
          // User is signed in
          userId = user.getUid();
          String provider = user.getProviderId();
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qxnG3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qxnG3.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/DTU0I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DTU0I.png" alt="enter image description here"></a></p>
  
  <p>i would appreciate some help in 1) formulating my rules, 2) if and how i should change my data structure, and finally 3) how to include the uid in the database reference which i'll use to write data to the database.</p>
  
  <p>thanks</p>