A
A
AndreyRafalsky132019-03-03 14:07:08
Android
AndreyRafalsky13, 2019-03-03 14:07:08

Why is displayName null after setting the value?

Good afternoon. I implement user registration using mail and password. Set username via

UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
                            .setDisplayName(name).build();
user.updateProfile(request);

But both in the database and when executing user.getDisplayName() I get null. Why doesn't updateProfile work?
Here is the complete code:
public void registerUserWithEmailAndPassword(String name, String email, String password){
        auth.createUserWithEmailAndPassword(email, password)
                .addOnSuccessListener(authResult -> {
                    FirebaseUser user = authResult.getUser();

                    UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
                            .setDisplayName(name).build();
                    user.updateProfile(request);

                    db.collection(UserCollection.COLLECTION_NAME)
                    .document(user.getUid()).set(user);

                    message.postValue(R.string.user_has_been_added);
                })
                .addOnFailureListener(exception -> {

                });
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question