signInWithUsernameNPassword method

  1. @override
Future<Response<UserCredential>> signInWithUsernameNPassword({
  1. required String username,
  2. required String password,
})
override

Implementation

@override
Future<Response<UserCredential>> signInWithUsernameNPassword({
  required String username,
  required String password,
}) async {
  final response = Response<UserCredential>();
  var mail = AuthConverter.toMail(username, "user", "org");
  if (AuthValidator.isValidEmail(mail)) {
    try {
      final result = await firebaseAuth.signInWithEmailAndPassword(
        email: mail ?? "example@user.org",
        password: password,
      );
      return response.withData(result, message: "Sign in successful!");
    } on FirebaseAuthException catch (_) {
      return response.withException(_.message, status: Status.failure);
    }
  } else {
    return response.withException("Username isn't valid!");
  }
}