I am using Firebase for authentication and I need to keep Delete Screen differently for Google Auth Users and Email Auth Users since the Google Auth Users don't need to provide their passwords. So, I wanted to know does FirebaseAuth offers some function that can distinguish if the user has used email or Google for Authentication?
1 Answers
1
votes
You can find out what provider a specific user account was created with from its FirebaseUser.providerId
property.
If you use account linking to allow a single user to sign in with multiple providers, you'll have to iterate over the FirebaseUser.providerData
array and check the UserInfo.providerId
for each of them.
The following function should help out in returning "password" for Firebase Email Auth users or "google.com" for Google Auth Users.
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
. . . .
. . . .
. . . .
Future<String> getAuthType() async {
final FirebaseUser firebaseUser = await _firebaseAuth.currentUser();
String authType = firebaseUser.providerData[1].providerId;
return authType;
}
You can use this information to your own advantage and create your widgets or Screens accordingly!