I am trying to implement the registration of a username in Firebase since it only gives me methods that are like the createUserWithEmailAndPassword(), but you can n
If you're using email/password auth with a username instead, you can simply index the users to email addresses in a sep path. Then when a user authenticates, look up their email in the index:
/user_to_email_index/$user_name/ https://www.firebase.com/docs/web/guide/login/custom.html
Try this,
DatabaseReference database = FirebaseDatabase.getInstance().getReference();
User user = new User(firebaseUser.getUid(),
firebaseUser.getEmail(),
, firstName, photoURL); // add value as bean object
database.child(ARG_USERS)
.child(firebaseUser.getUid())
.setValue(user)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
// user data updated in firebase
}
});
You cannot store custom data within a firebase user per se, according to firebase documentation
You cannot add other properties to the Firebase User object directly; instead, you can store the additional properties in your Firebase Realtime Database.
Since each registered user has a unique id that you can access with
FirebaseAuth.getInstance().getCurrentUser().getUid()
once the user logs in, you can create a table in the realtime database that stores data of each user using your User class. Then you can query the database for the logged in user using the snippet above for the Uid.
More info here: https://firebase.google.com/docs/auth/users