[PR #6626] feat(admin): add /admin/has-role endpoint #15036

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6626
Author: @chris23lngr
Created: 12/9/2025
Status: 🔄 Open

Base: mainHead: feat/user-has-role


📝 Commits (6)

  • 033d1b7 feat(admin): implement hasRole endpoint
  • eb71b3e style: remove blanks from admin example
  • 57a8565 fix(admin): add test for hasRole endpoint
  • 9c3dd01 docs: update admin docs to include hasRole
  • 1f3592c fix(admin): trim user roles in hasRole
  • ef71e57 fix(admin): update hasRole open api doc

📊 Changes

4 files changed (+224 additions, -0 deletions)

View changed files

📝 docs/content/docs/plugins/admin.mdx (+19 -0)
📝 packages/better-auth/src/plugins/admin/admin.test.ts (+63 -0)
📝 packages/better-auth/src/plugins/admin/admin.ts (+2 -0)
📝 packages/better-auth/src/plugins/admin/routes.ts (+140 -0)

📄 Description

Closes #6625


Summary by cubic

Adds an admin hasRole endpoint to check if a user has one or more roles. Exposes server and client APIs so admin flows can gate actions by role.

  • New Features
    • POST /admin/has-role with admin middleware.
    • Accepts userId and role(s) (string or array); validates input.
    • Requires an authenticated session; handles not-found users and missing roles.
    • Checks comma-separated user.role; returns success only if all requested roles are present.
    • Exposes auth.api.userHasRole and authClient.admin.hasRole with OpenAPI metadata.

Written for commit ef71e571af. Summary will update automatically 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/6626 **Author:** [@chris23lngr](https://github.com/chris23lngr) **Created:** 12/9/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/user-has-role` --- ### 📝 Commits (6) - [`033d1b7`](https://github.com/better-auth/better-auth/commit/033d1b7edf4a02f1531840dfaf59453bebfa2e88) feat(admin): implement hasRole endpoint - [`eb71b3e`](https://github.com/better-auth/better-auth/commit/eb71b3e0b0c9bbb6d4d13eea9a6779f950f117e4) style: remove blanks from admin example - [`57a8565`](https://github.com/better-auth/better-auth/commit/57a85656795d2dcc8fe9d1f5e9f026970454079b) fix(admin): add test for hasRole endpoint - [`9c3dd01`](https://github.com/better-auth/better-auth/commit/9c3dd01da23fd62bb6334cfc418eb1d4229f65ba) docs: update admin docs to include hasRole - [`1f3592c`](https://github.com/better-auth/better-auth/commit/1f3592c81a157f5fe5b910beebeeda29059f436e) fix(admin): trim user roles in hasRole - [`ef71e57`](https://github.com/better-auth/better-auth/commit/ef71e571af16b7c7ac32f9b24c88e55437d6b534) fix(admin): update hasRole open api doc ### 📊 Changes **4 files changed** (+224 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/admin.mdx` (+19 -0) 📝 `packages/better-auth/src/plugins/admin/admin.test.ts` (+63 -0) 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+2 -0) 📝 `packages/better-auth/src/plugins/admin/routes.ts` (+140 -0) </details> ### 📄 Description Closes #6625 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds an admin hasRole endpoint to check if a user has one or more roles. Exposes server and client APIs so admin flows can gate actions by role. - **New Features** - POST /admin/has-role with admin middleware. - Accepts userId and role(s) (string or array); validates input. - Requires an authenticated session; handles not-found users and missing roles. - Checks comma-separated user.role; returns success only if all requested roles are present. - Exposes auth.api.userHasRole and authClient.admin.hasRole with OpenAPI metadata. <sup>Written for commit ef71e571af16b7c7ac32f9b24c88e55437d6b534. Summary will update automatically 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-04-13 09:47:16 -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#15036