signIn method

  1. @override
Future<ThirdPartySessionModel?> signIn(
  1. String mail,
  2. String pass,
  3. SessionTypes type
)
override

Implementation

@override
Future<ThirdPartySessionModel?> signIn(
    String mail, String pass, SessionTypes type) async {
  try {
    var data = await this.api.signIn(mail, pass, type);

    // DATA
    if (data != null) {
      String? token = await data.getIdToken(true);

      ModLogger.d(
          "$TAG retrieved user: ${data.toString()} with token: ${token}");

      return ThirdPartySessionModel(
          token: token!,
          display: data.displayName ?? "",
          mail: data.email,
          pic: data.photoURL ?? "",
          mailValidationDone: data.emailVerified);

      // NO DATA
    } else {
      return null;
    }
  } on ModCancelledException catch (lce) {
    ModLogger.e(tag: TAG, msg: "${lce.toString()}", error: lce);
    return ThirdPartySessionModel.empty();
  } on InvalidEmailException catch (lce) {
    ModLogger.e(tag: TAG, msg: "${lce.toString()}", error: lce);
    throw ModDataException(ModErrorCodes.SIGNIN_INVALID_EMAIL, lce.message);
  } on UserDisabledException catch (lce) {
    ModLogger.e(tag: TAG, msg: "${lce.toString()}", error: lce);
    throw ModDataException(ModErrorCodes.SIGNIN_USER_DISABLED, lce.message);
  } on UserNotFoundException catch (lce) {
    ModLogger.e(tag: TAG, msg: "${lce.toString()}", error: lce);
    throw ModDataException(ModErrorCodes.SIGNIN_USER_NOT_FOUND, lce.message);
  } on WrongPasswordException catch (lce) {
    ModLogger.e(tag: TAG, msg: "${lce.toString()}", error: lce);
    throw ModDataException(ModErrorCodes.SIGNIN_WRONG_PASSWORD, lce.message);
  } on UnverifiedMailException catch (lce) {
    ModLogger.e(tag: TAG, msg: "${lce.toString()}", error: lce);
    throw ModDataException(ModErrorCodes.SIGNIN_UNVERIFIED_EMAIL, lce.message);
  } on PlatformException catch (pe) {
    ModLogger.e(tag: TAG, msg: "${pe.toString()}", error: pe);
    throw pe;
  } on Exception catch (e) {
    ModLogger.e(tag: TAG, msg: "${e.toString()}", error: e);
    throw ModDataException();
  }
}