Jm25E
Jm25E

Reputation: 19

is it possible to link firebase auth to the real-time Database

Is there a way i can do something like the following.

this the sample model of my firebase real-time database

The thing is, I can't figure out how to connect it on my authentication which contains my userIDs.

Can someone explain or give me an example?

Edit: code from comment on an answer:

Integer num1 = Integer.parseInt(edt1.getText().toString()); 
Integer num2 = Integer.parseInt(edt2.getText().toString()); 
Integer result = num1+num2; 
String data = Date+result; 
DateView.setText("Date Computed: " + Date + Hrs +"\n \n Computed Result: "+ result); 
HashMap<String, Integer> userMap = new HashMap<>(); 
userMap.put(Hrs, result); 
rootNode = FirebaseDatabase.getInstance(); 
reference = rootNode.getReference("Users").child("UserID").child("Logs");
reference.push().child(Date).setValue(userMap);

Upvotes: 0

Views: 55

Answers (2)

Frank van Puffelen
Frank van Puffelen

Reputation: 600006

You'll want to write the data under a node that uses the UID as the key. So the first step is to determine the UID of the current user:

String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();

And then you use that to write to the database:

rootNode = FirebaseDatabase.getInstance(); 
reference = rootNode.getReference("Users").child(uid).child("Logs");
reference.setValue(userMap);

This code matches with the JSON you show in your questions. If you want to auto-generate unique child nodes under Logs, you can use push() to do so.

Upvotes: 2

Muhammad Ahmed
Muhammad Ahmed

Reputation: 1048

Store the users in your database when user has done the sign up process. i.e

users
   userId1
      name XYZ
      email XYZ
      ........
    userId2
      name XYZ
      email XYZ
      ........

Upvotes: 2

Related Questions