title: Creating link between Firebase real-time database and authenticated users
body: <p>So far I have successfully implemented Firebase within my Android application, where I can add users to the Authentication portal through a <code>SignUpActivity</code>, and also add maintenance issues to the real-time database through a <code>MaintenanceActivity</code>.</p>
  
  <p>However, at present, none of the database data is linked to specific users, which is what I want to achieve.  So essentially at the moment when I log in as an arbitrary user, the same data will always come up.</p>
  
  <p>Presumably, and having read several other threads on this, the User UID will be required here and will need to be present for every maintenance record.</p>
  
  <p>I'm not sure, however, how I can implement this.  Possibly a layer of authentication needs implemented into the <code>MainActivity</code>?</p>
  
  <p>Finding it hard to get my head around this, so any help on this would be much appreciated. </p>
  
  <p><strong>SignUpActivity</strong></p>
  
  <pre><code>mDatabase = FirebaseDatabase.getInstance().getReference().child("users");
      final DatabaseReference[] ref = new DatabaseReference[1];
      final FirebaseUser[] mCurrentUser = new FirebaseUser[1];
      mAuth.createUserWithEmailAndPassword(email, password)
              .addOnCompleteListener(SignUpActivity.this, new OnCompleteListener&lt;AuthResult&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                      Toasty.info(getApplicationContext(), "creation of account was: " + task.isSuccessful(), Toast.LENGTH_SHORT).show();
                      if (task.isSuccessful()) {
                          mCurrentUser[0] = task.getResult().getUser();
                          ref[0] =mDatabase.child(mCurrentUser[0].getUid());
                          ref[0].child("email").setValue(email);
  
                          Intent intent = new Intent(SignUpActivity.this, MainActivity.class);
                          intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                          startActivity(intent);
                      }
                  }
              });
  </code></pre>