[PR #5673] feat(admin): Events for admin actions #14397

Open
opened 2026-04-13 09:27:18 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5673

State: open
Merged: No


closes https://github.com/better-auth/better-auth/issues/5444
linear https://linear.app/better-auth/issue/ENG-546/feat-impersonation-hooks-for-admin-plugin

Normally hooks can achieve the most of it, but there are extra work required such as making sure the endpoint was a successful request and whatnot. Extra work for our end users. Additionally we believe this is a fair ask, so I've started work on this.

image
  • tests
  • docs

This PR adds event options to the admin plugin to capture common events: impersonate start, impersonate end, ban user, unban user, user create, remove user.

Useful for:

  • cleanups
  • audit logging
  • notifications / email sending
image

Summary by cubic

Adds event callbacks to the admin plugin so apps can react to impersonation, bans, and user management. Addresses Linear ENG-546 by providing post-success impersonation events and reducing hook boilerplate.

  • New Features
    • New admin.events: impersonateStart, impersonateEnd, ban, unban, userCreate, userRemove.
    • Event payloads include adminSession and the target user; adminSession may be null for server-initiated calls, while ban/unban always include a session.
    • Ban/unban refetch the user to pass updated fields (banned, banReason, banExpires).
    • Added documentation with examples and comprehensive tests.
    • Event errors do not block admin operations.

Written for commit 143c0044bc. Summary will update on new commits.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5673 **State:** open **Merged:** No --- closes https://github.com/better-auth/better-auth/issues/5444 linear https://linear.app/better-auth/issue/ENG-546/feat-impersonation-hooks-for-admin-plugin Normally hooks can achieve the most of it, but there are extra work required such as making sure the endpoint was a successful request and whatnot. Extra work for our end users. Additionally we believe this is a fair ask, so I've started work on this. <img width="860" height="159" alt="image" src="https://github.com/user-attachments/assets/6f68f750-deb4-4f78-abca-bca4ce59fe8e" /> - [x] tests - [x] docs This PR adds event options to the admin plugin to capture common events: impersonate start, impersonate end, ban user, unban user, user create, remove user. Useful for: - cleanups - audit logging - notifications / email sending <img width="3008" height="4332" alt="image" src="https://github.com/user-attachments/assets/726dd76e-786d-457e-8d77-e2595ecba7cc" /> <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds event callbacks to the admin plugin so apps can react to impersonation, bans, and user management. Addresses Linear ENG-546 by providing post-success impersonation events and reducing hook boilerplate. - **New Features** - New admin.events: impersonateStart, impersonateEnd, ban, unban, userCreate, userRemove. - Event payloads include adminSession and the target user; adminSession may be null for server-initiated calls, while ban/unban always include a session. - Ban/unban refetch the user to pass updated fields (banned, banReason, banExpires). - Added documentation with examples and comprehensive tests. - Event errors do not block admin operations. <sup>Written for commit 143c0044bcac3958adb2af0482cb1e2f1506d1dc. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. -->
GiteaMirror added the pull-request label 2026-04-13 09:27:18 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#14397