user3145102
user3145102

Reputation: 43

Firebase provider

I'm creating an app that uses Firebase Authentication. I'd got provider's name with .getProvider() but Firebase was updated and now I'm using FirebaseAuth and FirebaseUser and I don't know how to get that name if I have login buttons (Google, Facebook, Twitter and email & password) in the same Activity.

Upvotes: 1

Views: 1963

Answers (2)

Akshay Sahai
Akshay Sahai

Reputation: 2350

Problem can be solved by using code -

FirebaseAuth mAuth = FirebaseAuth.getInstance();    
FirebaseUser user =mAuth.getCurrentUsers();    
String provider = user.getProviders().get(0);

Upvotes: 3

looptheloop88
looptheloop88

Reputation: 3810

You can get the provider id of the currently logged in user. It should look similar to the code snippet below:

    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Log.d(TAG, "Provider ID: " + user.getProviderId());
            }
        }
    };

Here's the Firebase class reference documentation: https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser.html#getProviderId()

Upvotes: 1

Related Questions