Home > Mobile >  How do I use googleSignIn.signOut()? (for Google OAuth in Flutter)
How do I use googleSignIn.signOut()? (for Google OAuth in Flutter)

Time:12-20

static final FirebaseAuth _auth = FirebaseAuth.instance;

static Future<dynamic> signOut() async {
  try {
    final googleSignIn = GoogleSignIn();

    await googleSignIn.signOut();
    await _auth.signOut();
  } catch (e) {
    return e;
  }
}

I had some questions:

  1. First of all, I could not find googleSignIn.signOut() anywhere in official google/flutter docs. I only found other people do that in YouTube, StackOverflow etc. So is this line 100% necessary, or does _auth.signOut() already do the job?

  2. What if user isn't signed in with Google? -> Tested, no problem (I just mentioned this, in case anyone wants to comment on it.

  3. Lastly, do both async signOut() functions need to be called in that specific order, or can I execute and await them in parallel for faster execution, like this:


static Future<dynamic> signOut() async {
  try {
    final googleSignIn = GoogleSignIn();
    await Future.wait([googleSignIn.signOut(), _auth.signOut()]);
  } catch (e) {
    return e;
  }
}

CodePudding user response:

To answer the first question:

Yes, actually _auth.signOut() already does the job. But, there is a problem, when you log in with Google (not the first time), it will automatically help you to use the Google account you used last time. You use googleSignIn.signOut() to let you choose which account to sign in with Google the next time.

To answer the third question (you answered the second question):

I don't know, but I think both can be used.

  • Related