PlatformException(popup_blocked_by_browser, Exception raised from GoogleAuth.signIn()

235 Views Asked by At

I keep on getting PlatformException(popup_blocked_by_browser, Exception raised from GoogleAuth.signIn() every first attempt when trying to use google_sign_in flutter package to sign in via Google. This only happens when I use safari, its fine on chrome. I'm wondering why it fails on the first attempt but works on the attempts after. And if I refresh my browser it fails again on the first attempt.

Here's my function using firebase auth and google sign in

@override
  Future<auth.User?> signInWithGoogle() async {
    final GoogleSignInAccount? googleUser =
        await _googleSignIn.signInSilently();
    final GoogleSignInAuthentication? googleAuth =
        await googleUser?.authentication;

    if (googleAuth == null) {
      return null;
    }

    final AuthCredential credential = GoogleAuthProvider.credential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );

    final UserCredential userCredential =
        await _firebaseAuth.signInWithCredential(credential);

    return auth.User(
      uid: userCredential.user?.uid,
      email: userCredential.user?.email,
    );
  }
0

There are 0 best solutions below