deleteEmailAccountByAuthUserId method

Future<void> deleteEmailAccountByAuthUserId(
  1. Session session, {
  2. required UuidValue authUserId,
  3. Transaction? transaction,
})

Deletes all email accounts by authentication user ID.

This will delete all email authentication accounts for the given auth user ID. Related data such as password reset requests will be automatically deleted due to cascade delete constraints.

Throws an EmailAccountNotFoundException if no accounts exist for the given auth user ID.

Implementation

Future<void> deleteEmailAccountByAuthUserId(
  Session session, {
  required UuidValue authUserId,
  Transaction? transaction,
}) async {
  return DatabaseUtil.runInTransactionOrSavepoint(
    session.db,
    transaction,
    (transaction) async {
      final deleted = await _utils.account.deleteAccount(
        session,
        email: null,
        authUserId: authUserId,
        transaction: transaction,
      );

      if (deleted.isEmpty) {
        throw EmailAccountNotFoundException();
      }
    },
  );
}