Search code examples
flutterdartfirebase-authenticationgoogle-authentication

Flutter-clicking on signin button with firebase google authentication always signs in automatically without the option to sign in as a different user


I have a signup/signin with google button on the main page and then when clicking, the user is given the option to put in the credentials for the google account. After signing in, the user is taken to a blank page with just a signout button where I call await FirebaseAuth.instance.signOut();

After the user clicks the signout button the user is taken back to the main page where they get the option to signin again.

The problem I have is once signed with a google account, even after clicking the signout button, the second time the user clicks on the signin button you are not given the option to sign in with a different google account, it automatically signs you in with the first account you signed in with. How do tackle this situation?

I have tried clearing the cache that runs when the user clicks on signout this way, but at this time it throws an error.

  Future<bool> signOut() async {
    await FirebaseAuth.instance.signOut();
    await FirebaseFirestore.instance.terminate();
    await FirebaseFirestore.instance.clearPersistence();
    return true;
  }

Also I am not using any of the firebase cloud firestore features, i just brought it in for clearing the cache.Is there any way we make this happen without using cloud firestore?


Solution

  • Can you try to disconnect the account before signing out:

    GoogleSignIn _googleSignIn = GoogleSignIn();
    await _googleSignIn.disconnect();
    await FirebaseAuth.instance.signOut();
    
    

    I asume you are using the google_sign_in plugin.