Firebase getDisplayName () returns empty

2

I have the following code that should return the user data logged in by Firebase, it returns the user with no problem, ID and Email, but the value of the name returns empty or null. As if the unnamed user was registered, but the user name usually appears in the registry. Does anyone know why? I already searched it and it looks like it has some bug with the Firebase getDisplayName. 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;
    }
    
asked by anonymous 19.11.2018 / 21:25

1 answer

1

After a search I discovered that this was a bug in some versions of Firebase, see here . It was introduced in the 9.8.0 version, so if you use the 9.6.1 version it does not. I can not tell if the bug has already been fixed, but try using the latest available version , which is the 16.0.4 .

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

I found some workarounds 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);
    }
}

Logging in 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 about the same subject here .

    
21.11.2018 / 13:56