Mike1982
Mike1982

Reputation: 459

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

I'm building a flutter app and I have options on my login page to create an account (which gets saved in firebase) or just sign in with Google (which also creates an account on firebase). On other pages, I have a logout button which only logs out of custom firebase account because it's calling this function:

Future<void> signOut() async {
    return _firebaseAuth.signOut();
  }

I also have this function for google sign out:

Future<void> signOutGoogle() async{
    return googleSignIn.signOut();
  }

variables declared at top:

 final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
  final GoogleSignIn googleSignIn = GoogleSignIn();
  FirebaseUser user;

Is there a way to determine if the user is signed in via Google or custom firebase? That way I'd be able to determine which function to call when the user clicks Logout.

Thanks in advance

Upvotes: 0

Views: 294

Answers (1)

pr0gramista
pr0gramista

Reputation: 9008

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

Upvotes: 3

Related Questions