firebaseAuthOnCacthError function

void firebaseAuthOnCacthError(
  1. FirebaseAuthException error, {
  2. Function? weakPasswordOption,
  3. Function? alreadyEmailExistOption,
  4. Function? userNotFound,
  5. Function? wrongPassword,
})

Implementation

void firebaseAuthOnCacthError(
  FirebaseAuthException error, {
  Function? weakPasswordOption,
  Function? alreadyEmailExistOption,
  Function? userNotFound,
  Function? wrongPassword,
}) {
  switch (error.code) {
    case 'weak-password':
      if (kDebugMode) print('The password provided is too weak.');
      weakPasswordOption;
      throw CustomFirebaseAuthException('The password provided is too weak.');
    case 'email-already-in-use':
      if (kDebugMode) print('The account already exists for that email.');
      alreadyEmailExistOption;
      throw CustomFirebaseAuthException('email-already-in-use');
    case 'user-not-found':
      if (kDebugMode) print('No user found for that email.');

      userNotFound;
      throw CustomFirebaseAuthException('No user found for that email.');
    case 'wrong-password':
      if (kDebugMode) print('Wrong password provided for that user.');
      wrongPassword;
      throw CustomFirebaseAuthException(
          'Wrong password provided for that user.');
    case 'requires-recent-login':
      if (kDebugMode) {
        print(
            'The user must reauthenticate before this operation can be executed.');
      }
      throw CustomFirebaseAuthException(
          'The user must reauthenticate before this operation can be executed.');
  }
}