-3

I made a register app in Android studio. For that I used firebase authentication method. When registering, the user has to enter his name, phone number, password and email. enter image description here

In authentication only the email is saved. enter image description here

If I can change this data to real time database I can save all the details. How to do it? I want a way to convert the details taken from this Authentication to a real time database. thank you.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
IZU99
  • 1
  • 3
  • I recommend searching for similar questions before posting your own: https://stackoverflow.com/search?q=%5Bfirebase-authentication%5D%5Bandroid%5D+save+user+to+database For example this question has some solid answers: https://stackoverflow.com/q/39076988/209103 – Frank van Puffelen Sep 22 '20 at 13:39

2 Answers2

0

you can retrieve data from auth using

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if (user != null) {
    // Name, email address, and profile photo Url
    String name = user.getDisplayName();
    String email = user.getEmail();
    Uri photoUrl = user.getPhotoUrl();
   }

here's the link for complete details about what you can get from auth user and later you can save it in your db.

you user must have signed in using signin methods.

Haider Saleem
  • 773
  • 1
  • 9
  • 17
0

Adding to @Haider Saleem answer:

You can also save all the values to Firebase Firestore (use the Firebase's Firestore instead of realtime database for better performance and lower cost). You would need the user's UID which you can get by:

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

Then you can create a document in Firestore with the user's UID as follows:

 FirebaseFirestore db = FirebaseFirestore.getInstance();
    db.collection(//collection Name)
            .document(uid)
            .set(//the object - HashMap or custom object))  

And get the data like:

 FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
 FirebaseFirestore db = FirebaseFirestore.getInstance();
    db.collection(//collection name)
            .document(user.getUid())
            .get()

I suggest you to read the following:

  1. Add Data to cloud Firestore
  2. Cloud Firestore Data Model
  3. Get Data with Cloud Firestore
s_o_m_m_y_e_e
  • 406
  • 4
  • 9