1

I want to add extra profile information to FirebaseAuth user profile, there is an update profile method like below, I want to add extra info ex: UserId, is there a option to do that?

val profileUpdates = UserProfileChangeRequest.Builder()
                .setDisplayName(usernameEditText.text.toString())
                .build()
VINNUSAURUS
  • 1,518
  • 3
  • 18
  • 38
  • 1
    There is no way to add your custom fields to the Firebase Authentication user records. Most developers store this additional information in the Firebase Database or Cloud Firestore. See https://stackoverflow.com/a/37420701, https://stackoverflow.com/a/43446255 – Frank van Puffelen Jul 14 '19 at 14:29

1 Answers1

1

If you created a user in the Firebase Auth then you get the following information:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
    for (UserInfo profile : user.getProviderData()) {
        // Id of the provider (ex: google.com)
        String providerId = profile.getProviderId();

        // UID specific to the provider
        String uid = profile.getUid();

        // Name, email address, and profile photo Url
        String name = profile.getDisplayName();
        String email = profile.getEmail();
        Uri photoUrl = profile.getPhotoUrl();
    }
}

Regarding updating profile, you can update the display name and photo url:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
        .setDisplayName("Jane Q. User")
        .setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
        .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.");
                }
            }
        });

You cannot update the uid, and if you want to add more data related to the user then the only option is to use the database and auth together.

You can check the docs for more information:

https://firebase.google.com/docs/auth/android/manage-users#update_a_users_profile

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134