I'm using Firebase authentication. The user can log in via e-mail password, google and facebook. How do I know if a user is logged in using an email-password? I looked at this answer
and i tried this:
for (UserInfo user: FirebaseAuth.getInstance().getCurrentUser().getProviderData()) {
if (!(user.getProviderId().equals("facebook.com") || user.getProviderId().equals("google.com"))) {
System.out.println("User is signed in with Email");
}
}
But when I use both google and email passwords if statement being true.
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");
}
}
Below is what works for me:
user.getProvider() returns firebase
user.getProviderData() returns some Id.
The list returned by user.getProviders() returns the login account type
Here's what I did:
@Override
protected void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null)
return;
for (int i = 0; i < currentUser.getProviders().size(); i++) {
if (!currentUser.getProviders().get(i).equals("google.com") && !currentUser.getProviders().get(i).equals("facebook.com")) {
//User signed in with a custom account
//Todo: call server DB or perform some task
} else
updateUI(currentUser);
}
// Todo: Complete login activity and switch to the main activity
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With