[PR #8045] [MERGED] refactor(admin): allow flexible admin impersonation #7708

Closed
opened 2026-03-13 13:46:35 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8045
Author: @jslno
Created: 2/18/2026
Status: Merged
Merged: 2/28/2026
Merged by: @Bekacru

Base: canaryHead: 02-18-2026/refactor-impersonate-admins


📝 Commits (2)

  • cda215a refactor(admin): allow flexible admin impersonation
  • de2050d chore: update docu

📊 Changes

5 files changed (+223 additions, -21 deletions)

View changed files

📝 docs/content/docs/plugins/admin.mdx (+14 -10)
📝 packages/better-auth/src/plugins/admin/access/statement.ts (+1 -0)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+185 -1)
📝 packages/better-auth/src/plugins/admin/routes.ts (+20 -9)
📝 packages/better-auth/src/plugins/admin/types.ts (+3 -1)

📄 Description

Summary by cubic

Make admin impersonation permission-driven. Adds the new impersonate-admins permission so only approved roles can impersonate admin users, while keeping the legacy flag for backward compatibility.

  • New Features

    • Introduced impersonate-admins permission in the user resource and default statements.
    • Routes now allow impersonating admins only if the requester has impersonate-admins or the legacy allowImpersonatingAdmins flag is true.
    • Updated docs with examples; added tests for both permission-based and legacy flows.
    • Marked allowImpersonatingAdmins as deprecated in types.
  • Migration

    • Grant impersonate-admins to roles that should impersonate admin users (e.g., super-admin).
    • Prefer permissions over allowImpersonatingAdmins; the flag will be removed in a future version.

Written for commit de2050df82. 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/8045 **Author:** [@jslno](https://github.com/jslno) **Created:** 2/18/2026 **Status:** ✅ Merged **Merged:** 2/28/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `02-18-2026/refactor-impersonate-admins` --- ### 📝 Commits (2) - [`cda215a`](https://github.com/better-auth/better-auth/commit/cda215ad4a5932aea440ee8ee5d13e6b7e24acde) refactor(admin): allow flexible admin impersonation - [`de2050d`](https://github.com/better-auth/better-auth/commit/de2050df820d20c62759d9d971e7ff264154f7f3) chore: update docu ### 📊 Changes **5 files changed** (+223 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/admin.mdx` (+14 -10) 📝 `packages/better-auth/src/plugins/admin/access/statement.ts` (+1 -0) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+185 -1) 📝 `packages/better-auth/src/plugins/admin/routes.ts` (+20 -9) 📝 `packages/better-auth/src/plugins/admin/types.ts` (+3 -1) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Make admin impersonation permission-driven. Adds the new impersonate-admins permission so only approved roles can impersonate admin users, while keeping the legacy flag for backward compatibility. - **New Features** - Introduced impersonate-admins permission in the user resource and default statements. - Routes now allow impersonating admins only if the requester has impersonate-admins or the legacy allowImpersonatingAdmins flag is true. - Updated docs with examples; added tests for both permission-based and legacy flows. - Marked allowImpersonatingAdmins as deprecated in types. - **Migration** - Grant impersonate-admins to roles that should impersonate admin users (e.g., super-admin). - Prefer permissions over allowImpersonatingAdmins; the flag will be removed in a future version. <sup>Written for commit de2050df820d20c62759d9d971e7ff264154f7f3. 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 13:46:35 -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#7708