I registered a user by using createUserWithEmailAndPassword()
and login using signInWithEmailAndPassword()
methods. Now when I login a user I need to get the username, mobile, that are stored in the user node. I could get the UId for each user, by using this how it possible to get the mentioned information in android?
all you have to do is use UserProfileChangeRequest
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
// Sign in success
FirebaseUser user = mAuth.getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(mName).build();
user.updateProfile(profileUpdates).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated.");
}
}
});
}
});
Then, to retrieve it, use this wherever required,
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// Name, email address etc
String name = user.getDisplayName();
String email = user.getEmail();
}
or you can create your own custom node.!
String currentuser = FirebaseAuth.getInstance().getUid();
//save user node after successful signup.
mFirebaseInstance.getReference("user").child(scurrentuser ).setValue(parameters);
databaseReference = FirebaseDatabase.getInstance().getReference().child("user").child(currentuser );
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot userSnapShot: dataSnapshot.getChildren()){
User user = userSnapShot.getValue(User.class);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With