Firebase user id does not use Firebase user uid

I am playing with FirebaseUI-Android and am asking a question about which ID to use when uniquely identifying users. FirebaseUI managed the authentication right and returned an object IdpResponse

. This can be, for example, Facebook, Twitter, phone, etc. This is thanks to everyone for this.

As it FirebaseUser.getUid()

can change when the user deletes / recreates their account, so I don't want to bind my data to the token FirebaseUser.getUid()

.

In the future, if I decide to let the user erase the account there, the uid will change when the user comes back and the entire user history for that user on my system is no longer available. Also in the future, if I move my system to site, then the uid won't be so convenient to be eligible?

I have now created this wrapper (code below) to create a unique ID extrapolated from the data inside IdpResponse

. Dunno really, but I believe it will never collide "id" if there is no Google2.0 for example. Twitter2.0 :) is correct. And at the same time, it is easier to mitigate errors in the system because id's are not UUIDs.

Is this the recommended way to handle the user ID issue. I really need some feedback and warnings about this.

@Override
public String getUserId() {
    String userId;
    FirebaseUser user = getInstance().getCurrentUser();
    if (user.getEmail() != null)
        // User sign in with E-Mail
        userId = user.getEmail().replace(".", ",");
    else if (user.getPhoneNumber() != null){
        // User sign in with Phone
        userId = user.getPhoneNumber();
    }else
        // User sign in with Twitter or Facebook 
        userId = user.getUid();
    return userId;
}

      

What worries me the most is Twitter or Facebook as I still need to use FirebaseUser.getUid()

. Is it IdpResponse.getIdpToken()

better for us?

+1


source to share


1 answer


As you mentioned in your post, using uid is not the best option. If the user deletes his account and than tries to create another account, another is generated uid

. Therefore, in this case, he lost the entire data history. The best way to identify users is to use email address

. The email address is unique, easy to use and, if required, in the future, to associate Google account

with Facebook account

and with Twitter account

, based on the email address, you can make an id. Since Firebase does not accept a character .

in a key, I suggest you encode your email address like this:

name@email.com → name @email, com

As you can probably see, I changed the dot symbol .

to coma ,

. To achieve this, I recommend that you use the following methods:



static String encodeUserEmail(String userEmail) {
    return userEmail.replace(".", ",");
}

static String decodeUserEmail(String userEmail) {
    return userEmail.replace(",", ".");
}

      

Hope it helps.

0


source







All Articles