signInWithEmailAndPassword method

  1. @override
Future<Either<AuthServiceSignInFailure, Unit>> signInWithEmailAndPassword(
  1. String email,
  2. String password
)
override

Implementation

@override
Future<Either<AuthServiceSignInFailure, Unit>> signInWithEmailAndPassword(
    String email, String password) async {
  try {
    // _hasGottenUserPrivate = false;

    var userCred = await _fbAuth.signInWithEmailAndPassword(
      email: email,
      password: password,
    );

    // Have to get this here so we'll know if the user finished setup yet
    // (await Get.find<UserRepositoryInt>().getUserById(credential.user!.uid)).fold(
    //   (failure) => currentUser.value = User(),
    //   (success) => currentUser.value = success,
    // );

    //TODO: duplicate code because the user could quit right after login

    // Create, Get the firebase user and return
    // var dbCreateResult = await Get.find<UserRepoInt>().createUserIfNotExist(User(
    //   id: userCred.user!.uid,
    //   email: email,
    // ));

    // Determine outcome
    // Either<AuthServiceSignInFailure, User> returnVal = dbCreateResult.fold(
    //   (failure) {
    //     return failure.maybeWhen(
    //       orElse: () => left(AuthServiceSignInFailure.databaseError()),
    //     );
    //   },
    //   (success) {
    //     currentUser.value = success;
    //     return right(success);
    //   },
    // );

    // Finally return

    if (userCred.user == null) {
      return left(AuthServiceSignInFailure.userNotFound);
    }

    await waitForCanCheckLoginState();

    // UserPrivate returnValUser =
    //     (await Get.find<UserRepoInt>().getUserPrivateById(userCred.user!.uid)).fold(
    //   (failure) => throw Exception(),
    //   (success) => success,
    // );

    //await refreshCurrentUser();

    return right(unit);

    //return right(currentUser.value);
  } on fb_auth.FirebaseAuthException catch (e) {
    switch (e.code) {
      case 'invalid-email':
        logd('signInWithEmailAndPassword invalid-email');
        return left(AuthServiceSignInFailure.invalidEmail);
      case 'user-not-found':
        logd('signInWithEmailAndPassword user-not-found');
        return left(AuthServiceSignInFailure.userNotFound);
      case 'wrong-password':
        logd('signInWithEmailAndPassword wrong-password');
        return left(AuthServiceSignInFailure.wrongPassword);
      case 'user-disabled':
        logd('signInWithEmailAndPassword user-disabled');
        return left(AuthServiceSignInFailure.userDisabled);
      default:
        logd('signInWithEmailAndPassword default exception');
        return left(AuthServiceSignInFailure.unexpected);
    }
  } catch (e) {
    loge(e);
    return left(AuthServiceSignInFailure.unexpected);
  }
}