Reputation: 6181
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
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..
Upvotes: 5
Views: 4734
Reputation: 598765
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()
.
Upvotes: 7