Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase returns multiple IDs, Which is unique one?

I am new to Firebase and i am trying to connect Firebase Auth api into my application, I have followed documentation from newer updated documentation from Official site and all things work fine.

I have done successful SignIn and in my dashboard i got all users after they login.

My problem is i am so confuse about various IDs returned from Firebase

Code is as follows :

 for (UserInfo profile : user.getProviderData()) {
                // Id of the provider (ex: google.com)
                String providerId = profile.getProviderId();
                //if Id of the provider is firebase it means we have successfully get back data after saving in firebbase hence we continue to app
                if(providerId.equals("firebase")) {
                    // UID specific to the provider
                    Other.SavePref(this, "LoginToken", profile.getUid());

                    // Name, email address, and profile photo Url
                    String name = profile.getDisplayName();
                    String email = profile.getEmail();
                    Uri photoUrl = profile.getPhotoUrl();

                    Log.e("userinfo", "  ::  " + profile.getUid()+ " :: " + name + " :: " + email + " :: " + photoUrl);
                }
            };

as in above code i am only checking if providerId is firebase then i store information, but if i don't do it, it will give me data two times

  1. from Firebase
  2. from Google also

and i got two userIds if i use this method : profile.getUid(), I just want to know which one is unique? and which i should use?

And someone can proposed a way for what to do after getting successful signin at application side, It would be very helpful..

like image 590
TapanHP Avatar asked Aug 26 '16 05:08

TapanHP


People also ask

Is Firebase UID unique?

The user's Firebase UID. This is unique within a project. Dictionary of all the identities that are associated with this user's account.

How do you uniquely identify a user in Firebase?

actually you are on the right way, for unique id you can use user. getUid() this id will always unique for every user as per their register credentials. Token is basically depends on device which will help you into send notification feature.

What is UUID in Firebase?

UUID is autogenerated based on timestamp and some entropy. UUID's can be sorted based on creation time, this helps to maintain indexes in Firebase. UUID is not some hash of for example the email address, or facebook id or other.

Where is Firebase auth data stored?

The user data for firebase authentication is stored in firebaseLocalStorageDb in IndexedDB .


1 Answers

A user can sign in with multiple providers. Each provider generates its own unique ID for that user. You can access these under the user info for each provider.

On top of that Firebase Authentication also generates its own unique ID for the user. No matter which provider the user signed in with, they'll end up with the same UID for that. You can find this under FirebaseUser.getUid().

To identify a user, you'd normally use the value from FirebaseUser.getUid(), so in your snippet: user.getUid().

like image 153
Frank van Puffelen Avatar answered Nov 13 '22 15:11

Frank van Puffelen