How to Determine If a Firebase User Is Signed in Using Facebook Authentication

How to check if a user is logged in via Facebook in Firebase Auth

This is how you can do it:

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

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

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:

FirebaseAuth.getInstance().getCurrentUser().getProviderId()

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("facebook.com")) {
System.out.println("User is signed in with Facebook");
}
}

Firebase Auth check if new user on Facebook login

You can detect if a user is new or existing as follows:

firebase.auth().signInWithPopup(provider)
.then(function(result) {
console.log(result.additionalUserInfo.isNewUser);
})
.catch(function(error) {
// Handle error.
});

For more on this refer to the documentation.

Is there a way to determine if a user is signed in via custom firebase account or google account in flutter?

You can access FirebaseUser property called providerData which type is List<UserInfo>. UserInfo has a providerId which is fe. google.com, facebook.com, password (email) or phone.

You can find those values looking up the code.

print(user.providerData[0].providerId) // -> fe. google.com

How to determine if a Firebase user is signed in using email and password authentication

The provider ID for email+password is password. So:

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


Related Topics



Leave a reply



Submit