signIn static method

Future<UserCredential?> signIn({
  1. String? clientID,
  2. String? serverClientID,
})

Implementation

static Future<UserCredential?> signIn({
  String? clientID,
  String? serverClientID,
}) async {
  try {
    YurLoading(
      loadingStatus: LoadingStatus.show,
      message: "Signing in with Google",
    );
    // Trigger the Google Sign-In process
    final GoogleSignInAccount? googleUser = await GoogleSignIn(
      clientId: clientID,
      serverClientId: serverClientID,
    ).signIn();

    if (googleUser == null) {
      YurLoading(loadingStatus: LoadingStatus.dismiss);
      // The user canceled the sign-in process
      return null;
    }

    // Obtain the authentication details from the Google Sign-In request
    final GoogleSignInAuthentication googleAuth =
        await googleUser.authentication;

    // Create a new credential using the obtained authentication details
    final AuthCredential credential = GoogleAuthProvider.credential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );

    // Sign in to Firebase with the credential
    final UserCredential userCredential =
        await FirebaseAuth.instance.signInWithCredential(credential);

    YurLoading(loadingStatus: LoadingStatus.dismiss);

    return userCredential;
  } catch (error) {
    YurLoading(loadingStatus: LoadingStatus.dismiss);
    // Handle any errors that might occur during the sign-in process
    YurLog(name: "signInWithGoogle", 'Error signing in with Google: $error');
    return null;
  }
}