In case of Login and Registration app, how can we store the details of each user uniquely in firebase real-time database? when I try to login with a different user the data is being overwritten.
How can I Solve This?
In case of Login and Registration app, how can we store the details of each user uniquely in firebase real-time database? when I try to login with a different user the data is being overwritten.
How can I Solve This?
If you are logged in with a user with FirebaseAuth
you can use getUid()
to get a unique identifier for that logged in user, then you can write to the database with that UID, the next time a user logs in with the same account, it will write on that same unique destination. If the user logs in with another account, another new unique identification will be created for that specific account.
Example
FirebaseAuth mAuth;
mAuth = FirebaseAuth.getInstance().getCurrentUser();
String userID = mAuth.getUid();
mDatabaseRef.child("semOneOne").child(userID).child("name").setValue("Gastón");
Important: Sometimes getCurrentUser() could be null, and so on your userID, so, make sure you check if the user is logged in first before getting the userID
For more information please check on how to Manage Users in Firebase