Firebase getDisplayName() returns empty

Asked

Viewed 147 times

2

I have the following code that should return the user data logged in by Firebase, it returns the user without any problem, the ID and the Email, but the value of the name returns empty or null. As if the user with no name was registered, but the user’s name is usually included in the register. Does anyone know why? I already searched and it seems that there is a bug with getDisplayName from Firebase. Already got a solution?

public static FirebaseUser getUsuarioAtual() {
        FirebaseAuth usuario = ConfiguracaoFirebase.getFirebaseAutenticacao();
        return usuario.getCurrentUser();
    }

    public static Usuario getDadosUsuarioLogado() {
        FirebaseUser firebaseUser = getUsuarioAtual();

        Usuario usuario = new Usuario();
        usuario.setId(firebaseUser.getUid());
        usuario.setEmail(firebaseUser.getEmail());
        usuario.setNome(firebaseUser.getDisplayName());

        return usuario;
    }

1 answer

0


After a search I discovered that this was a bug in some versions of Firebase, see here. He was introduced in the version 9.8.0, then if you use the version 9.6.1 it does not occur. I do not know if the bug has been fixed, but try to use the latest version available, which is the 16.0.4.

On this page I mentioned above some users reported problems also with the method FirebaseUser.getPhotoUrl(), beyond the method FirebaseUser.getDisplayName().

I found some alternative solutions in Soen answers, see if any solves your problem.

Using FirebaseUser.getProviderData() (link):

FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
    String displayName = user.getDisplayName();
    Uri profileUri = user.getPhotoUrl();

    for (UserInfo userInfo : user.getProviderData()) {
        if (displayName == null && userInfo.getDisplayName() != null) {
            displayName = userInfo.getDisplayName();
        }
        if (profileUri == null && userInfo.getPhotoUrl() != null) {
            profileUri = userInfo.getPhotoUrl();
        }
    }

    accountNameTextView.setText(displayName);
    if (profileUri != null) {
        Glide.with(this)
                .load(profileUri)
                .fitCenter()
                .into(userProfilePicture);
    }
}

Working out and logging again (link):

// Comando para deslogar o usuário atual.
FirebaseAuth.getInstance().signOut();
// Depois disso logar novamente:
// https://firebase.google.com/docs/auth/android/password-auth

And another question on the same subject here.

  • C.Oli, has any solution worked for you? Leave it commented here if yes or if no, please to help others who find this same problem.

  • I managed to solve by deleting the profiles already created and creating again, it started to return normally the value of the name. With the method of dislodging and re-logging tbm works.

  • Using FirebaseUser.getProviderData() didn’t work for me

Browser other questions tagged

You are not signed in. Login or sign up in order to post.