Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android firebase 12.0.0 - mAuth.getCurrentUser().getProvider() method is removed, how to get provider names?

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 ?

like image 644
j2emanue Avatar asked Mar 26 '18 04:03

j2emanue


2 Answers

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;
        }
    }
like image 132
Bob Snyder Avatar answered Nov 16 '22 00:11

Bob Snyder


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

enter image description here

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;
    }
}

}

like image 35
Chaaruu Jadhav Avatar answered Nov 16 '22 00:11

Chaaruu Jadhav