[PR #4653] [MERGED] fix(admin): change the order of role and user id check when both are provider on userHasPermission #13754

Closed
opened 2026-04-13 09:07:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4653
Author: @Bekacru
Created: 9/14/2025
Status: Merged
Merged: 9/14/2025
Merged by: @Bekacru

Base: canaryHead: fix/admin


📝 Commits (3)

  • 11bd8cc fix(admin): change the order of role and user id check when both are provider on userHasPermission
  • c549836 change to and
  • 7fdca24 chore: lint

📊 Changes

1 file changed (+10 additions, -8 deletions)

View changed files

📝 packages/better-auth/src/plugins/admin/admin.ts (+10 -8)

📄 Description

Summary by cubic

Fixes userHasPermission in the admin plugin to correctly handle requests when both role and userId are provided and to enforce stricter auth checks. HTTP requests now require a session; internal calls without a session must include userId and role.

  • Bug Fixes
    • Require a session for HTTP requests; otherwise return UNAUTHORIZED.
    • For non-HTTP/internal calls without a session, return BAD_REQUEST when userId or role is missing.
    • When role is provided, build the user from role and userId before attempting a DB lookup to avoid unnecessary queries and honor explicit role input.

🔄 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/4653 **Author:** [@Bekacru](https://github.com/Bekacru) **Created:** 9/14/2025 **Status:** ✅ Merged **Merged:** 9/14/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/admin` --- ### 📝 Commits (3) - [`11bd8cc`](https://github.com/better-auth/better-auth/commit/11bd8ccdffb6aa678f6b36e3df8ab30227df22a4) fix(admin): change the order of role and user id check when both are provider on userHasPermission - [`c549836`](https://github.com/better-auth/better-auth/commit/c5498369086de3004b5ea3995eea55a580937da8) change to and - [`7fdca24`](https://github.com/better-auth/better-auth/commit/7fdca245d46862a5d72289381dd4d9cbd60bb880) chore: lint ### 📊 Changes **1 file changed** (+10 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+10 -8) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Fixes userHasPermission in the admin plugin to correctly handle requests when both role and userId are provided and to enforce stricter auth checks. HTTP requests now require a session; internal calls without a session must include userId and role. - Bug Fixes - Require a session for HTTP requests; otherwise return UNAUTHORIZED. - For non-HTTP/internal calls without a session, return BAD_REQUEST when userId or role is missing. - When role is provided, build the user from role and userId before attempting a DB lookup to avoid unnecessary queries and honor explicit role input. <!-- 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-04-13 09:07:48 -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#13754