firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.63k stars 1.83k forks source link

displayName returning null firebase-ui-auth 1.0.0 #409

Closed jetav8r closed 7 years ago

jetav8r commented 7 years ago

I'm trying to add a user using the Firebase auth and it returns the displayName as null, even though it asks for it via the UI on sign up. Any ideas why and how to fix? Here's the code I am using to do this:

startActivityForResult( AuthUI.getInstance() .createSignInIntentBuilder() .setProviders(Collections.singletonList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build())) .build(), RC_SIGN_IN);

and in the Activity for Result....

protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { // user is signed in!

    //save user
    saveUser();

    startMainActivity();
    return;
}

save user code is as follows:

private void saveUser(){ FirebaseUser fUser = FirebaseAuth.getInstance().getCurrentUser(); final User user = new User(); if (fUser.getDisplayName() != null) { user.setUserName(fUser.getDisplayName()); } else { Log.e("FB_info", "User has no display name"); } user.setUserEmail(fUser.getEmail());

final DatabaseReference userRef = FirebaseDatabase.getInstance().getReference(FirebaseRefs.getUsersRef()).child(fUser.getUid());
userRef.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        if(!dataSnapshot.exists()){
            userRef.updateChildren(user.toMap());
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {

    }
});

} Any idea why the display name is returning null?

SUPERCILEX commented 7 years ago

Do you ever call setValue() to upload the name to your database?

samtstern commented 7 years ago

@jetav8r I don't see an obvious bug here, but this is also not likely to be an issue with FirebaseUI. Please raise this question on StackOverflow as this is more of a troubleshooting request than a library issue.

jetav8r commented 7 years ago

I can't upload the value to the database because the user.getDisplayName() is always null

On Fri, Nov 18, 2016 at 2:55 PM, Alex Saveau notifications@github.com wrote:

Do you ever call setValue() to upload the name to your database?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/firebase/FirebaseUI-Android/issues/409#issuecomment-261663700, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmXxT5uQ1t1Cjw82ilaPeU3q9q_DGKyks5q_izkgaJpZM4K22mI .

jetav8r commented 7 years ago

I'm gonna disagree with you here, since the only interface is with the Firebase Auth UI and it doesn't return the displayName when I call getDisplayName...this comes directly from your methods. The UI asks for the users First and Last name, but it always returns null. thanks for closing the case so quickly without any resolution

On Fri, Nov 18, 2016 at 4:49 PM, Sam Stern notifications@github.com wrote:

Closed #409 https://github.com/firebase/FirebaseUI-Android/issues/409.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/FirebaseUI-Android/issues/409#event-865173344, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmXxSEpNetXWUkKgh1_pXyV2Cy_qA31ks5q_keZgaJpZM4K22mI .

SUPERCILEX commented 7 years ago

FirebaseUI is a free and open-source library that provides a layer of abstraction over the Firebase platform. The getDisplayName() method you are talking about comes from the closed source FirebaseUser class. You can find the documentation for that class here. I would highly recommend looking over the general documentation for Firebase authentication here.

jetav8r commented 7 years ago

Got it...thanks for the information Alex...I'll see if I can narrow it down from there...

On Fri, Nov 18, 2016 at 8:28 PM, Alex Saveau notifications@github.com wrote:

FirebaseUI is a free and open-source library that provides a layer of abstraction over the Firebase platform. The getDisplayName() method you are talking about comes from the closed source FirebaseUser class. You can find the documentation for that class here https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser. I would highly recommend looking over the general documentation for Firebase authentication here https://firebase.google.com/docs/auth/android/start/.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/FirebaseUI-Android/issues/409#issuecomment-261692721, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmXxZqbGqodK0QmrtnTBuFVEtiRltyVks5q_nrzgaJpZM4K22mI .

SUPERCILEX commented 7 years ago

@samtstern @jetav8r, Actually it looks like this is a Firebase bug so I'm using this post to explain what's going on in the bug report I submitted. (@samstern for all I know you're the guy they send the support case to so I might as well post it here 😄) Also, this issue should be reopened as a [KNOW ISSUE] since I was able to recreate the issue. Could you or @amandle confirm?

Steps to reproduce for Firebase support:

  1. Create a profile change request builder with a non-null name and call the FirebaseUser#updateProfile() method.
  2. FirebaseUser#getDisplayName() returns null
  3. Log out and log back in
  4. FirebaseUser#getDisplayName() now returns the updated name from the profile change request builder. From this behavior, it looks like the display name is only being updated server side and the changes aren't propagating to the local user on the device.

For a full mcve, see https://github.com/firebase/FirebaseUI-Android/blob/master/auth/src/main/java/com/firebase/ui/auth/ui/email/RegisterEmailActivity.java#L149

PS: since FirebaseUI is more of a cve without the minimal part, I could quickly write a simpler demo app if necessary.

Update

It looks like this issue was introduced in the Firebase Android SDK v9.8.0 See my comment for temporary workarounds.

Update 2

Upon further investigation, it appears that the FirebaseUser#reload() method is broken. FirebaseUser#updateProfile() returns the same task that reload() does so I'm making the assumption that you guys just return the reload() task at the end of updateProfile(). If not, then the reload() method should also be fixed. At the moment, the only way to update the profile on the device is to force a refresh by logging out and then back in.

jetav8r commented 7 years ago

okay, so I'm not losing my mind...LOL... I guess I'm trying to figure out how to access that First Name/Last Name data to store with the user's email and uID when they create the account. I will need their name for later access via a search function and don't want to have to enter it manually or through another screen if possible

Wayne

On Fri, Nov 18, 2016 at 9:28 PM, Alex Saveau notifications@github.com wrote:

@samtstern https://github.com/samtstern @jetav8r https://github.com/jetav8r, Actually it looks like this is a Firebase bug so I'm using this post to explain what's going on in the bug report I submitted. (@samstern https://github.com/samstern for all I know you're the guy they send support case to so I might as well post it here 😄) Also, this issue should be reopened as a [KNOW ISSUE] since I was able to recreate the issue. Could you or @amandle https://github.com/amandle confirm?

Steps to reproduce for Firebase support:

  1. Create a profile change request builder with a non-null name and call the FirebaseUser#updateProfile() method.
  2. FirebaseUser#getDisplayName() returns null
  3. Log out and log back in
  4. FirebaseUser#getDisplayName() now returns the updated name from the profile change request builder. From this behavior, it looks like the display name is only being updated server side and the changes aren't propagating to the local user on the device.

For a full mcve, see https://github.com/firebase/FirebaseUI-Android/blob/ master/auth/src/main/java/com/firebase/ui/auth/ui/email/ RegisterEmailActivity.java#L149

PS: since FirebaseUI is more of a cve without the minimal part, I could quickly write a simpler demo app if necessary.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/FirebaseUI-Android/issues/409#issuecomment-261694842, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmXxetGqDyQ0WZXYDpYkT_JapJOPpcDks5q_oj1gaJpZM4K22mI .

SUPERCILEX commented 7 years ago

@jetav8r Temporary workarounds include downgrading FirebaseUI to a version that uses play services v9.6.1 (see the compatibility table) or overriding the the FirebaseUI gradle dependencies by including them in your app.gradle file with different versions (aka v9.6.1).

jetav8r commented 7 years ago

Okay, thanks...please keep me posted when a fix becomes available as the displayName will be an integral part of an app I'm developing. Thank you!

Wayne

On Fri, Nov 18, 2016 at 9:46 PM, Alex Saveau notifications@github.com wrote:

@jetav8r https://github.com/jetav8r Temporary workarounds include downgrading FirebaseUI to a version that uses play services v9.6.1 (see compatibility table https://github.com/firebase/FirebaseUI-Android#compatibility-with-firebase--google-play-services-libraries) or overriding the the FirebaseUI gradle dependencies https://github.com/firebase/FirebaseUI-Android/blob/master/auth/build.gradle#L34 by including them in your app.gradle file with different versions (aka v9.6.1).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/FirebaseUI-Android/issues/409#issuecomment-261695421, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmXxYFR1OM1xMJUHWMo7G6Uny96hw6zks5q_o0ggaJpZM4K22mI .

samtstern commented 7 years ago

@SUPERCILEX thank you for the detailed reproduction steps

@jetav8r I apoligize for prematurely closing this issue, as @SUPERCILEX said it is actually an issue with the underlying Firebase SDK and not FirebaseUI which is why I said it was unrelated, but it's an issue all the same.

jetav8r commented 7 years ago

No problem... please notify me when there's a good fix for this issue, as I definitely need to be able to access the user's full name when they initially input it when creating their account with email. Thank you!

Wayne

On Mon, Nov 21, 2016 at 10:37 AM, Sam Stern notifications@github.com wrote:

@SUPERCILEX https://github.com/SUPERCILEX thank you for the detailed reproduction steps

@jetav8r https://github.com/jetav8r I apoligize for prematurely closing this issue, as @SUPERCILEX https://github.com/SUPERCILEX said it is actually an issue with the underlying Firebase SDK and not FirebaseUI which is why I said it was unrelated, but it's an issue all the same.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/FirebaseUI-Android/issues/409#issuecomment-262027066, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmXxaqL0786j9lpALC9Afzctj8DrPu9ks5rAeT7gaJpZM4K22mI .

samtstern commented 7 years ago

Hey all this looks like a regression in Firrebase Auth. It was introduced in version 9.8.0 so the last time it worked would be 9.6.1. Right now we don't know of a workaround besides logging out and back in but if we figure one out I'll post it.

kirtan403 commented 7 years ago

@samtstern Should we post an issue in the Firebase bug tracker or its already in the process?

kirtan403 commented 7 years ago

@SUPERCILEX As per your workaround, will that be fine to include 2 gradle dependencies, one with 10.0.0 and one with 9.6.1 for firebase-auth? Won't that conflict? Or am I understanding wrong?

SUPERCILEX commented 7 years ago

@kirtan403 Unfortunately, all of your play services/firebase dependencies will have to be 9.6.1 (see https://github.com/firebase/FirebaseUI-Android/issues/414#issuecomment-262283040 for an example override).

And yes, I've submitted a bug and Firebase says: "We're investigating".

aidanas commented 7 years ago

Hi, can we have a link to that bug report please so we can track the progress on it.

kirtan403 commented 7 years ago

I am using some newly introduced APIs, so it would be difficult for me to downgrade.

Let's wait till status changes from "We're investigating"

SUPERCILEX commented 7 years ago

@aidanas sadly, no. Firebase doesn't have an open issue tracker just like they aren't open source. I will definitely update this post and submit a PR if necessary once I get updates from Firebase though.

SUPERCILEX commented 7 years ago

I just got an update today:

Hi Alex,

Thanks for your patience here. As we checked, unfortunately, this is a known issue on our end and we already created a ticket so we can track and handle this accordingly. Apologies for the inconvenience this might have caused you.

As a workaround, you can proceed using an older Firebase version (9.6.1). Another solution is to manage your profile information as you would any other info by using Firebase Database. Also, to log-out and then log-in the user upon changing the profile information. I know this is undesirable way to handle this and again, we really sorry for this.

Just keep an eye out to our release notes for any future updates. For any further concerns, feel free to reach out to us. Have a great day!

Thanks, Garwin

kirtan403 commented 7 years ago

I really just don't understand that how such a serious bug can take so many release cycles to go into the production. I know because I have contacted them for a bug relating to offline transaction failure and it took almost 4 months to get an update in the android sdk. They should definitely have a known issues section on their website.

jetav8r commented 7 years ago

Agreed...this is a pretty serious bug and it shouldn't take that long to fix and do an SDK update!

On Tue, Nov 29, 2016 at 10:38 AM, kirtan403 notifications@github.com wrote:

I really just don't understand that how such a serious bug can take so many release cycles to go into the production. I know because I have contacted them for a bug relating to offline transaction failure and it took almost 4 months to get an update in the android sdk. They should definitely have a known issues section on their website.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/FirebaseUI-Android/issues/409#issuecomment-263658192, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmXxYTUgFPtrHRAIaeSBL8GT8iK-z7Xks5rDHEcgaJpZM4K22mI .

r3dm4n commented 7 years ago

I'm also having this issue. Hope to see a fix soon.

AndroidPat commented 7 years ago

Some users reported the same issue with .getPhotoUrl() returning null ( even though there is a picture publicly available in google+/facebook) but it was closed. It worked for me before implementing Auth UI. I spent a whole day trying to figure out what's causing it without luck. Can someone confirm it's working with FirebaseUI for Android? Link to the closed issue #159

kirtan403 commented 7 years ago

@Buli1212 Yes I can confirm.

I have also tried and photo url was also null. This is the firebase sdk issue. I have also contacted support and they told they are aware of this issue and are working on it but with no timeline provided (as always). Hope this issue will be fixed in the next android sdk update.

r3dm4n commented 7 years ago

@Buli1212 @kirtan403 I don't have any issues with .getPhotoUrl, only with getDisplayName for email log in. It's funny that it works in other cases(Facebook and Google) and also, if the user logs in after username was created, the name is populated in the database.

jetav8r commented 7 years ago

This is really getting annoying... I hope they fix this soon as a I have a client who wants to strictly use email login and no Facebook/Google for authentication. Hard to explain to him why the users don't show up because of a Firebase bug. PLEASE FIX THIS SOON!!!!

Wayne

On Wed, Dec 7, 2016 at 9:03 AM, Alex notifications@github.com wrote:

@Buli1212 https://github.com/Buli1212 @kirtan403 https://github.com/kirtan403 I don't have any issues with .getPhotoUrl, only with getDisplayName for email log in. It's funny that it works in other cases(Facebook and Google) and also, if the user logs in after username was created, the name is populated in the database.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/firebase/FirebaseUI-Android/issues/409#issuecomment-265506088, or mute the thread https://github.com/notifications/unsubscribe-auth/AHmXxYql9tQZ6FBA_IBTJkBi-UUZ2tlNks5rFubEgaJpZM4K22mI .

Akshit94 commented 7 years ago

@SUPERCILEX @samtstern since you both are the contributors I want to suggest something on the issue. After several tries I came to know that re-authenticating the user at the time of their registration may fix the problem (temporarily of-course until a fixed version of the Firebase SDK is released). So adding the following code at the end of the registerUser() inside the RegisterEmailActivity.java file may fix the problem: `

    final FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
    AuthCredential credential = EmailAuthProvider
            .getCredential(firebaseUser.getEmail(), password);

    firebaseUser.reauthenticate(credential)
            .addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                    Log.d(TAG, firebaseUser.getDisplayName());
                }
            });`

Downsides being it may increase the request time. Please do comment whether the solution would work or not.

dcalano commented 7 years ago

Thank you, I just ran into this using 1.0.1

SUPERCILEX commented 7 years ago

They fixed it!!!!!!! It'll probably come out in 10.1.0 near the end of the month.

Hi Alex,

Thank you for bringing this up. As we checked, we are now done with the fix, but are currently waiting for the release. Unfortunately, I cannot provide you any specific details on its availability. You can keep an eye out on our release notes for any future updates.

Again, apologies for any inconvenience here. Have a great day!

Thanks, Garwin

alcacer0 commented 7 years ago

I am still having this problem.. Can someone confirm if it has been solved? Thanks

SUPERCILEX commented 7 years ago

It hasn't been solved because the updated play services hasn't come out yet.

samtstern commented 7 years ago

Hey all,

Since at this point we're just waiting for an SDK update and I can confirm the fix is definitely coming I am going to close this issue, there's nothing more FirebaseUI can do here. The best place to watch for updates is here: https://firebase.google.com/support/release-notes/android

Lizzyyang commented 7 years ago

I got the same problems by using startActivityForResult( AuthUI.getInstance() .createSignInIntentBuilder() .build(), SIGN_IN_REQUEST_CODE ); I can not got the getDisplayName(), but it work when I sign out and sign in again. Do you have any solutions

felipe-gouveia commented 6 years ago

Issue still happening on SDK version 11.6.2. :(

siddhantkushwaha commented 6 years ago

This workaround I found on stack-overflow did the job for me. :)

`

mAuth.getCuurentUser().reload().addOnSuccessListener( new OnSuccessListener() { @Override public void onSuccess(Void aVoid) {

                     String email = user.getEmail();
                     String name = user.getDisplayName();
                     if(name=="") name="No One.";

                     userEmailView.setText(email);
                     userNameView.setText(name);
                 }
             }
     );

`

KyleMari commented 6 years ago

I can manage to show getDisplayName() from currentUser who's signed in to Google and Facebook providers directly. However, the getDisplayName() is null when I link an anonymous user to Google and Facebook.

//assuming an anonymous user is already signed in final AuthCredential credential = FacebookAuthProvider.getCredential(fbToken.getToken()); mFirebaseAuth.getCurrentUser().linkWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { Toast.makeText(LoginActivity.this, mFirebaseAuth.getCurrentUser().getDisplayName(), Toast.LENGTH_SHORT).show(); } else { //Log.w(TAG, "signInWithCredential:failure", task.getException()); } } });

Is there any workaround for this, in the case of linking an anonymous user to the providers stated?

Gaetano-Dati commented 6 years ago

I have this issue as well while linking from anonymous to real provider like Facebook or Google.

Gaetano-Dati commented 6 years ago

I have this issue as well while linking from anonymous to real provider like Facebook or Google.

sfstanley1 commented 6 years ago

any update on this yet ?

mp3killa commented 5 years ago

Hmmm this is a 3 year old bug and seems trivial enough to fix it, why is it still broken?

samtstern commented 5 years ago

@mp3killa this is a very old issue and we did fix it at the time. If you believe there is a regression please open a new issue so we can look into it.

Geeodorah commented 4 years ago

Hiya,

Im a bit confused what the current state of this bug is now. What makes it a bit weird for me is that I see different behaviour with the same implementation. So I have 1 account that returns the name properly and a second account which doesn't...

Anyway would like to know if I can use this feature or not

Thanks in advance

SMehranB commented 2 years ago

Sad to say that this issue still exists with version 7.2.0 This is such a fundamental functionality of the library and it should be on a critical checklist before rollout to avoid regressions when there has been so many issues for so long. And by looking at this thread, I believe it is safe to say that it is just not reliable to use.