Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase + Flutter : get platform user used to sign in

I have an app with 3 sign in methods: Google, Facebook & mail. I want to show the users that are signed in with mail a different screen. Is it possible to get the sign in method form the package firebase authentication?

I know I can fix this by using firestore & checking if a statement is true or false. But that will cost me a read every time a user opens the app...

like image 454
Karel Debedts Avatar asked Jul 29 '19 11:07

Karel Debedts


1 Answers

Firebase has a special property providerId. But, as mentioned @GazihanAlankus it always returns firebase.

And, the property firebaseUser.providerData[1].providerId sometimes not exists (for example when user used anonymous login).

So, we should use appropriate approaches, for example:

FirebaseUser user = await _firebaseAuth.currentUser();

if (user.providerData.length < 2) {
  // do something
}
else {
  print(res.providerId);  
}

The list of values, that are returned by property providerId:

EmailAuthProviderID: password
PhoneAuthProviderID: phone
GoogleAuthProviderID: google.com
FacebookAuthProviderID: facebook.com
TwitterAuthProviderID: twitter.com
GitHubAuthProviderID: github.com
AppleAuthProviderID: apple.com
YahooAuthProviderID: yahoo.com
MicrosoftAuthProviderID: hotmail.com

I got this list from the cool research here What is the full list of provider id's for firebase.UserInfo.providerId?

like image 122
awaik Avatar answered Nov 02 '22 18:11

awaik