Firebase-android-sdk: FirebaseUser.getUid() sometimes returns the email instead of uid

Created on 21 Mar 2019  ·  12Comments  ·  Source: firebase/firebase-android-sdk

Step 1: Are you in the right place?

I think so.

Step 2: Describe your environment

  • Android Studio version: 3.3
  • Firebase Component: Auth, Database
  • Component version: Auth & Database 16.1.0

Step 3: Describe the problem

I have actually the same problem as already described in the issue from the ios-sdk:
Issue-Link

At the start of my application and directly after sign up I initialize a firebase RTDB
reference and write/read values to a node dedicated to the user.

I use FirebaseAuth to get my current user with getCurrentUser() and _if this is not null_, I get the
uid using: FirebaseUser.getUid().

Using this UID, I create the Database reference. The first part of the reference is static
and completely built it looks like: USER_AUTH/{uid}

This worked flawless until now. Going through my latest crash reports I stumpled upon
a new exception:

Fatal Exception: com.google.firebase.database.DatabaseException
Invalid Firebase Database path: [email protected]. Firebase Database paths must not contain '.', '#', '$', '[', or ']'

I have only a few users, that are affected by this problem. The other 15~k daily users are not affected.

Steps to reproduce:

Usually FirebaseUser.getUid() returns values like: _w3I1VcsO0CgABFtilZUnfLplDDh2_.
Now it returns email addresses.

  • I noticed that all users affected by the problem have @gmail addresses.
  • I use multiple providers (Google, Facebook, Phone, Mail-Link), but all are Email Provider users
  • the email addresses shown in the crash logs are all quite long
  • registration dates of the users: 9/16/18 , 1/23/19, 1/27/19
  • all the affected users have Android OS version 8.0.0 or 8.1.0

Relevant Code:

I don't think a piece of code will help to figure out the problem. But I am doing something like this:

  public void foo(){
        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        if(user != null){
            String uid = user.getUid();
            DatabaseReference reference = FirebaseDatabase.getInstance().getReference("USER_AUTH").child(uid);
            reference.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    // do something
                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {
                    // do something
                }
            });
        }
    }
auth bug

All 12 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@SteveBurkert thanks for reporting this! I think we can both agree this will be extremely tricky to debug and I am not quite sure where to start. It's interesting that https://github.com/firebase/firebase-ios-sdk/issues/598 says a similar thing.

Could you possibly email me (samstern at google dot com) with your project ID and a few of these email addresses?

This is also happening on one of our projects. There is no specific way to replicate it.

  • Same that all the crashes are @gmail addresses.
  • We initially had just the Email Provider for sign in, but recently added Google Sign In. Nonetheless we've seen some crashes before it was added.
  • Email length is usuall <15-20characters>@gmail.com
  • Registration dates of the recent users showing the issue: March/2019 , May/2019
  • Similarly, the affected users have Android OS version 8.0.0 or 8.1.0 along with 9.0

We're using the following Firebase versions currently:

    implementation 'com.google.firebase:firebase-core:16.0.9'
    implementation 'com.google.firebase:firebase-auth:17.0.0'
    implementation 'com.google.firebase:firebase-database:17.0.0'
    implementation 'com.google.firebase:firebase-messaging:18.0.0'
    implementation 'com.google.firebase:firebase-storage:17.0.0'

@samtstern Would really appreciate your help. Thanks!

cc @malcolmdeck @lsirac

Hey.
Is there any progress on this once?

I recently stumbled upon users having a UID instead of an e-mail. So the other way around.
But maybe this is related to the topic.

exmaple_

@SteveBurkert could you send me an email (samstern at google dot com) with your Firebase Project ID and the Firebase UID for that Google user? This would be a good concrete case for us to investigate. Thank you!

Happy New Year. I sent it to you! Sorry for late response.

Just to follow up publicly here, after talking to @SteveBurkert over email the confusing record was actually a gmail account like this one:

7yal7g5ga2nccsks3hlfxewy2[...]@cloudtestlabaccounts.com

This account was created by Firebase Test Lab, which is used under the hood by Google Play pre-launch reports.

I faced with the same issue

Fatal Exception: com.google.firebase.database.DatabaseException
Invalid Firebase Database path: t*[email protected]. Firebase Database paths must not contain '.', '#', '$', '[', or ']'

on next code:

database.getReference().child("dev").child("user").child(FirebaseAuth.getInstance().getUid()) .child("data");

Follow up: Faced the issue again, with a clearly normal E-mail:

Fatal Exception: com.google.firebase.database.DatabaseException
Invalid Firebase Database path: n******@gmail.com. Firebase Database paths must not contain '.', '#', '$', '[', or ']'

So basically the same as SerhiiMobile.

Is there any progress on this @samtstern ?

Some insights:

  • over 50 occurrences in last month
  • device distribution: 46% HUAWAI, 39% motorola, 15% HDM global
  • os distribution: 85% android 8, 15% android 9
  • 100% device in background

Hey there, Malcolm from the Firebase team here! I'm taking a look at this, but I'm having a hard time reproducing it. We had an issue way back in 2017 where the email and displayName would be switched in the User object because of a serialization error, but the version of firebase-auth you're using shouldn't result in this issue anymore since it was fixed more than a year before the 17.0.0 release. Also, you're seeing UID/email mixups, which doesn't track with that old error at all.

I'm trying to dig around and see if there are other clues to why this is happening, but I'm having trouble reproducing it and it's hard to reason about previous version releases. I'll spend another little while taking a look to see if I can find anything, but this is a tough one - I've never seen anything like this.

In the meantime, the best I can suggest is updating to the latest version of Auth and seeing if the issue persists - I know that that's not a particularly satisfying answer, but it's the best one I have at the moment. :/ The only other alternative I have is that you can refresh the user before trying to grab the UID - that's not a great solution either, but since you aren't seeing incorrect UIDs on fresh sign-ins it would probably provide the desired behavior.

~Malcolm

Please drop a note if you are continuing to see the issue

Was this page helpful?
0 / 5 - 0 ratings