logInWithFacebook method

Future<AuthUser?> logInWithFacebook()

Starts the Sign In with Facebook Flow.

Throws a LogInWithGoogleFailure if an exception occurs.

Implementation

Future<AuthUser?> logInWithFacebook() async {
  try {
    // Trigger the sign-in flow
    final loginResult = await _facebookAuth.login();

    if (loginResult.status == LoginStatus.success) {
      // Create a credential from the access token
      final OAuthCredential credential =
          FacebookAuthProvider.credential(loginResult.accessToken!.token);
      // Once signed in, return the UserCredential
      final userCredentials =
          await FirebaseAuth.instance.signInWithCredential(credential);
      return userCredentials.user == null
          ? AuthUser.empty
          : userCredentials.user!.toUser;
    }

    return null;
  } on FirebaseAuthException catch (e) {
    throw LogInWithGoogleFailure.fromCode(e.code);
  } catch (_) {
    throw const LogInWithGoogleFailure();
  }
}