signInByGoogle static method

Future<bool> signInByGoogle()

Implementation

static Future<bool> signInByGoogle() async {
  if (Platform.isWindows) {
    log("Login by Google is not supported in Desktop Version");
    return false;
  } else {
    try {
      if (!await GoogleSignIn().isSignedIn()) {
        await GoogleSignIn().disconnect();
      }
    } on Exception catch (_) {}

    final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
    final GoogleSignInAuthentication? googleAuth =
        await googleUser?.authentication;

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

    var auth = await FirebaseAuth.instance.signInWithCredential(credential);
    if (auth.user != null) {
      currentUser = GlobalUser(
        uid: FirebaseAuth.instance.currentUser!.uid,
        displayName: FirebaseAuth.instance.currentUser!.displayName,
        email: FirebaseAuth.instance.currentUser!.email,
        phoneNumber: FirebaseAuth.instance.currentUser!.phoneNumber,
        photoURL: FirebaseAuth.instance.currentUser!.photoURL,
      );
      return true;
    }
  }
  return false;
}