doAttemptLogin method

  1. @override
Future<AuthResponse> doAttemptLogin(
  1. BuildContext context, {
  2. dynamic credentials,
})
override

Implementation

@override
Future<AuthResponse> doAttemptLogin(BuildContext context,
    {credentials}) async {
  try {
    if (infoX.isMacOS) {
      // The Google SignIn library doesn't work with MacOS
      // ignore: unused_local_variable
      final creds = ThirdPartyCreds.googleSignIn.credentials;
      final result = await DesktopWebviewAuth.signIn(GoogleSignInArgs(
          clientId: creds.clientId ?? illegalState('No clientId'),
          redirectUri: creds.redirectUrl ?? illegalState('No redirect')));

      var ocred = fb.GoogleAuthProvider.credential(
        accessToken: result!.accessToken,
        idToken: result.idToken!,
      );
      return AuthResponse.success(ocred);
    } else {
      final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
      _log.info("Got response from sign in: ${googleUser?.id}");
      if (googleUser == null) {
        return AuthResponse.cancelled();
      }

      final GoogleSignInAuthentication googleAuth =
          await googleUser.authentication.timeout(3.seconds);

      _log.info("Waited for authentication (with timeout): ${googleUser.id}");
      final credential = fb.GoogleAuthProvider.credential(
        accessToken: googleAuth.accessToken,
        idToken: googleAuth.idToken,
      );

      _log.info("Got firebase creds: ${googleUser.id}");

      return AuthResponse.success(credential);
    }
  } catch (e, stack) {
    _log.severe("Error with google sign in: $e", e, stack);
    rethrow;
  }
}