in firebase_version = '11.8.0'
there was a method called mAuth.getCurrentUser().getProviders()
i could call to get the list of provider names. so for email provider it was "password" and for facebook is was "facebook.com", etc
the method call was like this:
final FirebaseUser currentUser = mAuth.getCurrentUser()
for (String provider : this.currentUser.getProviders()) {
//i was looping over all the providers this way, and then storing the provider string in my db
}
but now in the latest firebase_version = '12.0.0'
the method getProviders()
is not available.
How can i get the provider names as string ?
Use FirebaseUser.getProviderData(). It returns a list of UserInfo, each contains a string Provider ID.
For example:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
List<? extends UserInfo> infos = user.getProviderData();
for (UserInfo ui : infos) {
if (ui.getProviderId().equals(GoogleAuthProvider.PROVIDER_ID)) {
return true;
}
}
This is how I am able to get provider id of logged in user. You can use similar provider ids which are shared by iOS developers. Like google.com, password, microsoft.com, Facebook.com etc
private void providerId() { FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
String providerID = user.getProviderData().get(1).getProviderId();
switch (providerID) {
case "google.com":
break;
case "password":
break;
case "microsoft.com":
break;
default:
break;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With