How to determine if a Firebase user is signed in using facebook authentication

The question:

I am using firebase from google and I have some trouble with user authentication. After logging with facebook I obtain FirebaseUser in AuthStateListener, but how can I detect if this user is logged via facebook or differently?

As @Frank van Puffelen said FirebaseAuth.getInstance().getCurrentUser().getProviderId()
should return “facebook”, but in my case it returns “firebase”. Now I cannot figure out what’s the reason of this behavior. When I got FacebookToken I do something like this:

        AuthCredential credential = FacebookAuthProvider.getCredential(facebookToken.getToken());
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    public void onComplete(@NonNull Task<AuthResult> task) {

                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {



And afterthat before onComplete() method is called, my AuthStateListener gets user which provider id is not “facebook” as it should be. Am I doing something wrong? I followed official google documentation

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

In version 3.x and later a single user can be signed in with multiple providers. So there is no longer the concept of a single provider ID. In fact when you call:


It will always return firebase.

To detect if the user was signed in with Facebook, you will have to inspect the provider data:

for (UserInfo user: FirebaseAuth.getInstance().getCurrentUser().getProviderData()) {
  if (user.getProviderId().equals("")) {
    System.out.println("User is signed in with Facebook");

Method 2

In my app, I use Anonymous Firebase accounts. When I connect Firebase auth with a Facebook account or Google Account I am checking like the following:

for (UserInfo user: FirebaseAuth.getInstance().getCurrentUser().getProviderData()) {

  if (user.getProviderId().equals("")) { 
    //For linked facebook account
    Log.d("xx_xx_provider_info", "User is signed in with Facebook");

  } else if (user.getProviderId().equals("")) { 
    //For linked Google account
    Log.d("xx_xx_provider_info", "User is signed in with Google");


Method 3

For me, the following solution is working.
First, get the firebase user object if you have’nt already:

FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser firebaseUser = mAuth.getCurrentUser();

Now use the following on the FirebaseUser object to get the sign in provider:



It will return password,, and for email, google, facebook and twitter respectively.

Method 4

Sharing for FirebaseAuth targeting version 6.x.x (Swift 5.0), year 2020:

I use Auth.auth().currentUser?.providerData.first?.providerID.

This will return password if logged in via email. And if via Facebook.

Method 5

There exist information in the responding Intent.

Refer to following snippet:

The responseCode is either “phone”, “”, “”, or “”.

    `import com.firebase.ui.auth.AuthUI;
    import com.firebase.ui.auth.IdpResponse;
    protected void onActivityResult(final int requestCode, int resultCode, Intent 
    data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == RC_SIGN_IN) {
            IdpResponse response = IdpResponse.fromResultIntent(data);
            if (resultCode == RESULT_OK) { 
                String providerCode = response.getProviderType();

Method 6

Most recent solution is:

As noted here

var uiConfig = {
        callbacks: {
          signInSuccessWithAuthResult: function(authResult, redirectUrl) {
            var providerId = authResult.additionalUserInfo.providerId;

and for display in page

firebase.auth().onAuthStateChanged(function (user) {
      if (user) {
        user.getIdToken().then(function (idToken) {

          $('#user').text(welcomeName + "(" + localStorage.getItem("firebaseProviderId")+ ")");

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment