monicahq/monica · error · ValidationException

You can't delete yourself.

Error message

You can't delete yourself.

What it means

DestroyUser removes a user from the account (destroying vaults they solely manage). validate() rejects the case where user_id equals author_id — the authenticated account administrator trying to delete their own user — with a ValidationException that Laravel renders as a 422.

Source

Thrown at app/Domains/Settings/ManageUsers/Services/DestroyUser.php:64

    {
        $this->data = $data;

        $this->validate();
        $this->destroyAllVaults();
        $this->destroy();
    }

    private function validate(): void
    {
        $this->validateRules($this->data);

        /** @var User */
        $user = $this->account()->users()
            ->findOrFail($this->data['user_id']);
        $this->user = $user;

        if ($this->data['user_id'] === $this->data['author_id']) {
            throw new ValidationException(
                'You can\'t delete yourself.',
            );
        }
    }

    /**
     * We will destroy all the vaults the user is the manager of, IF there are
     * no other managers of the vault.
     */
    private function destroyAllVaults(): void
    {
        $vaultsUserIsManagerOf = $this->user->vaults()
            ->wherePivot('permission', Vault::PERMISSION_MANAGE)
            ->get();

        foreach ($vaultsUserIsManagerOf as $vault) {
            try {
                $vault->users()

View on GitHub (pinned to e08e917341)

Solutions

  1. Target another user's id; to remove yourself, have another administrator perform the deletion
  2. Exclude the current user from the deletable list in the UI
  3. Compare user_id against the authenticated user before submitting
Defensive patterns

Strategy: validation

Validate before calling

// Validate before calling: never send the acting author's own id
if ($data['user_id'] === $data['author_id']) {
    throw ValidationException::withMessages([
        'user_id' => "You can't delete yourself.",
    ]);
}

Type guard

function isSelfDeletionAttempt(array $data): bool
{
    return $data['user_id'] === $data['author_id'];
}

Try / catch

use Illuminate\Validation\ValidationException;

try {
    app(DestroyUser::class)->execute($data);
} catch (ValidationException $e) {
    // already a 422: message 'You can\'t delete yourself.' — keep and re-display to the user
    throw $e;
}

Prevention

When it happens

Trigger: Issuing the delete-user request with target user_id identical to the authenticated author's id: a UI passing the current user's id, or a cleanup script iterating users including the acting one.

Common situations: Frontend defaulting the selected user to the current admin, bulk scripts not excluding the acting author, or id mix-ups between the author_id and user_id fields.

Related errors


AI-assisted analysis of monicahq/monica@e08e917341 (2026-08-17). Data as JSON: /api/errors/0ab3e4cc11701a59. Report an issue: GitHub.