authClient.admin.removeUser doesn't trigger beforeDelete

I'm using the admin plugin. It has authClient.admin.removeUser functionality. the problem is that I set up user beforeDelete to delete all of the images from my s3 bucket before removing the user and it doesn't work. It works if and only if the user deletes himself manually.

user deletion from the admin side:
async function handleDelete() {
    await authClient.admin.removeUser({
      //@ts-expect-error
      userId,
    });
    router.push("/admin/dashboard");
    router.refresh();
    setOpen(false);
  }


better-auth instance:
const auth = betterAuth({
user: {
  deleteUser: {
        beforeDelete: async (user) => {
          // images deletion logic
          const userChatRoomImages = (
            await db.chatRoom.findUnique({
              where: {
                userId: Number(user.id),
              },
              select: { images: true },
            })
          )?.images;
          userChatRoomImages?.map(async (image) => await deleteImage(image.key));
        },
        enabled: true,
      },
  }
})
Was this page helpful?