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
How to Set Android Camera Orientation Properly
Simple Parse JSON from Url on Android and Display in Listview
Going to Home Screen Programmatically
Ideal Way to Set Global Uncaught Exception Handler in Android
How to Set Image Button Backgroundimage for Different State
How to Bring an Activity to Foreground (Top of Stack)
Programmatically Select Item Listview in Android
Android:Loading an Image from the Web with Asynctask
Unsupportedoperationexception: Can't Convert to Dimension: Type=0X1
How to Pass the Values from One Activity to Previous Activity
Counting Chars in Edittext Changed Listener
How to Create a Listview with Rounded Corners in Android
How to Maintain Fragment State When Added to the Back Stack
Android Webview: Handling Orientation Changes