confirmAccountDeletion function

Future<AuthAccountDeletionConfirmed> confirmAccountDeletion({
  1. required AuthStore store,
  2. required String userId,
  3. required String token,
  4. DateTime? now,
})

Confirms and executes account deletion.

This deletes the user and all associated data. This operation cannot be undone.

Implementation

Future<AuthAccountDeletionConfirmed> confirmAccountDeletion({
  required AuthStore store,
  required String userId,
  required String token,
  DateTime? now,
}) async {
  final normalizedUserId = userId.trim();

  if (normalizedUserId.isEmpty) {
    throw AuthFlowException('invalid_request');
  }

  final deletionStore = store is AuthUserDeletionCoordinatorHost
      ? store as AuthUserDeletionCoordinatorHost
      : null;
  if (deletionStore == null) {
    throw AuthFlowException('account_deletion_unavailable');
  }
  final deleted = await deletionStore.userDeletionCoordinator
      .confirmAndDeleteUser(userId: normalizedUserId, token: token, now: now);
  if (!deleted) {
    throw AuthFlowException('invalid_deletion_token');
  }

  return AuthAccountDeletionConfirmed(
    userId: normalizedUserId,
    deleted: deleted,
  );
}