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

Open
opened 2026-03-13 12:49:21 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5673
Author: @ping-maxwell
Created: 10/30/2025
Status: 🔄 Open

Base: canaryHead: feat/admin-events


📝 Commits (10+)

  • 1bff3ea feat(admin): Events for admin actions
  • 13ee007 fix: change requests
  • 0a9fe0c Merge branch 'canary' into feat/admin-events
  • 8ab9e39 Merge branch 'canary' into feat/admin-events
  • d09ad44 Merge branch 'canary' into feat/admin-events
  • aca7439 Merge branch 'canary' into feat/admin-events
  • 5251bb4 Merge branch 'canary' into feat/admin-events
  • 4048c75 Merge branch 'canary' into feat/admin-events
  • 1fddd9c Merge branch 'canary' into feat/admin-events
  • a531f31 Merge branch 'canary' into feat/admin-events

📊 Changes

5 files changed (+1314 additions, -3 deletions)

View changed files

📝 docs/content/docs/plugins/admin.mdx (+158 -0)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+1011 -0)
📝 packages/better-auth/src/plugins/admin/admin.ts (+1 -1)
📝 packages/better-auth/src/plugins/admin/routes.ts (+68 -2)
📝 packages/better-auth/src/plugins/admin/types.ts (+76 -0)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5673 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 10/30/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/admin-events` --- ### 📝 Commits (10+) - [`1bff3ea`](https://github.com/better-auth/better-auth/commit/1bff3ea2c830ab8a886daf70796bfc0667657573) feat(admin): Events for admin actions - [`13ee007`](https://github.com/better-auth/better-auth/commit/13ee007e3537c18bc4fce5ce57ec3c4e1c6f2a14) fix: change requests - [`0a9fe0c`](https://github.com/better-auth/better-auth/commit/0a9fe0c45a3e18d324c048fe4ce220f401ca769b) Merge branch 'canary' into feat/admin-events - [`8ab9e39`](https://github.com/better-auth/better-auth/commit/8ab9e3926eb023464bf22d62e7d95e3b34a4f331) Merge branch 'canary' into feat/admin-events - [`d09ad44`](https://github.com/better-auth/better-auth/commit/d09ad44703ec6ea8bf24189cb081bf48b52f6a1e) Merge branch 'canary' into feat/admin-events - [`aca7439`](https://github.com/better-auth/better-auth/commit/aca7439b53c49ae1c10ca6907a189ed25eda9a90) Merge branch 'canary' into feat/admin-events - [`5251bb4`](https://github.com/better-auth/better-auth/commit/5251bb4aed5204b165680fbc6d450dd9bb801eaa) Merge branch 'canary' into feat/admin-events - [`4048c75`](https://github.com/better-auth/better-auth/commit/4048c7500d083f8b864dc05608081c28a7744dd0) Merge branch 'canary' into feat/admin-events - [`1fddd9c`](https://github.com/better-auth/better-auth/commit/1fddd9c7b9e4f786e23959c515e97c87cd1572f0) Merge branch 'canary' into feat/admin-events - [`a531f31`](https://github.com/better-auth/better-auth/commit/a531f3133c37fcb5fa10f6a36d8c6190bbbc7a83) Merge branch 'canary' into feat/admin-events ### 📊 Changes **5 files changed** (+1314 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/admin.mdx` (+158 -0) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+1011 -0) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/admin/routes.ts` (+68 -2) 📝 `packages/better-auth/src/plugins/admin/types.ts` (+76 -0) </details> ### 📄 Description 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. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:49:21 -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#6150