Skip to content Skip to sidebar Skip to footer

How To Get Linked Account With Current User In Firebase

I am trying to link my firebase account to my google account and facebook account, and till here everything is working fine.here is my code how I am linking accounts. mAuth.getCurr

Solution 1:

Now I want to get, is my current account is linked to facebook or google?

You can check the provider id to see if the user is signed in with Google or Facebook like this:

FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser != null) {
    for (UserInfo userInfo : firebaseUser.getProviderData()) {
        if (userInfo.getProviderId().equals("google.com")) {
            Log.d(TAG, "User is signed in with Google");
        } elseif(userInfo.getProviderId().equals("facebook.com")) {
            Log.d(TAG, "User is signed in with Facebook");
        }
    }
}

You can also use the following code:

List<?extends UserInfo> infos = user.getProviderData();
for (UserInfo ui : infos) {
    if (ui.getProviderId().equals(GoogleAuthProvider.PROVIDER_ID)) {
        Log.d(TAG, ui.getProviderId());
    }
}

Post a Comment for "How To Get Linked Account With Current User In Firebase"