Admin Plugin: Get user by id support #1806

Closed
opened 2026-03-13 09:04:51 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @kebench on GitHub (Aug 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

I'm using better auth admin plugin for my user management. It works well given the features however, there is a use case where I have to fetch the user information using a user ID and display the user info in our app. It wasn't available in the admin plugin (we also checked the documentation) and we have to make a separate API for it.

Describe the solution you'd like

  • Add a client method for fetching the user info by ID as seen in the code below.
const { data: user, error } = await authClient.admin.getUser({
    userId: id
});
  • Expected user object response would have the structure below. It contains the user info in the user table along with the accounts connected to the user.
id: string
name: string
email: string
emailVerified: string
image: string
role: string
createdAt: Date
updatedAt: Date
accounts: Array<{
   accountId: string
   providerId: string
}>
  • Since there is a client method proposed, adding an API endpoint for fetching the user info by ID would be the next step (this should only be possible if the user role is admin or has a capability to manage users).

Describe alternatives you've considered

Alternative we considered (and some implemented):

  • Querying the database directly

    • Pros: Gives full control over user data.
    • Cons: Bypasses the admin plugin’s abstraction.
    • Cons: Duplicates logic and increases maintenance overhead.
  • Using existing "list users" endpoint with "searchValue" and "searchField"

    • Pros: Leverages existing functionality without adding new endpoints.
    • Cons: Without proper indexing, lookups (e.g., by email or name) require full table scans and can be slow for large datasets.
    • Cons: Inefficient for large datasets (fetching many users just to get one).
    • Cons: Adds unnecessary complexity on the client side.
  • Handling role/capability checks in the application layer

    • Pros: Keeps the plugin untouched.
    • Cons: Responsibility shifts out of the plugin, leading to inconsistent security patterns.
    • Cons: Harder to maintain and reason about authorization logic.
  • Relying solely on the admin dashboard for user details

    • Pros: Works for manual lookups.
    • Cons: Not viable for programmatic use cases.
    • Cons: Breaks the automation and scalability needs of the app.

Additional context

No response

Originally created by @kebench on GitHub (Aug 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I'm using better auth admin plugin for my user management. It works well given the features however, there is a use case where I have to fetch the user information using a user ID and display the user info in our app. It wasn't available in the admin plugin (we also checked the documentation) and we have to make a separate API for it. ### Describe the solution you'd like - Add a client method for fetching the user info by ID as seen in the code below. ``` const { data: user, error } = await authClient.admin.getUser({ userId: id }); ``` - Expected user object response would have the structure below. It contains the user info in the user table along with the accounts connected to the user. ``` id: string name: string email: string emailVerified: string image: string role: string createdAt: Date updatedAt: Date accounts: Array<{ accountId: string providerId: string }> ``` - Since there is a client method proposed, adding an API endpoint for fetching the user info by ID would be the next step (this should only be possible if the user role is admin or has a capability to manage users). ### Describe alternatives you've considered Alternative we considered (and some implemented): - Querying the database directly - Pros: Gives full control over user data. - Cons: Bypasses the admin plugin’s abstraction. - Cons: Duplicates logic and increases maintenance overhead. - Using existing "list users" endpoint with "searchValue" and "searchField" - Pros: Leverages existing functionality without adding new endpoints. - Cons: Without proper indexing, lookups (e.g., by email or name) require full table scans and can be slow for large datasets. - Cons: Inefficient for large datasets (fetching many users just to get one). - Cons: Adds unnecessary complexity on the client side. - Handling role/capability checks in the application layer - Pros: Keeps the plugin untouched. - Cons: Responsibility shifts out of the plugin, leading to inconsistent security patterns. - Cons: Harder to maintain and reason about authorization logic. - Relying solely on the admin dashboard for user details - Pros: Works for manual lookups. - Cons: Not viable for programmatic use cases. - Cons: Breaks the automation and scalability needs of the app. ### Additional context _No response_
GiteaMirror added the plugin label 2026-03-13 09:04:51 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Aug 29, 2025):

I'm pretty sure we have a PR in the works for this, if I can find it I'll post it here

@ping-maxwell commented on GitHub (Aug 29, 2025): I'm pretty sure we have a PR in the works for this, if I can find it I'll post it here
Author
Owner

@ping-maxwell commented on GitHub (Aug 29, 2025):

https://github.com/better-auth/better-auth/pull/2587

@ping-maxwell commented on GitHub (Aug 29, 2025): https://github.com/better-auth/better-auth/pull/2587
Author
Owner

@himself65 commented on GitHub (Sep 4, 2025):

See cf7f2f1181

@himself65 commented on GitHub (Sep 4, 2025): See https://github.com/better-auth/better-auth/commit/cf7f2f118147b6a79a99fcf48898408f038390f5
Author
Owner

@kebench commented on GitHub (Sep 4, 2025):

A huge thank you for including this in the latest release!

@kebench commented on GitHub (Sep 4, 2025): A huge thank you for including this in the latest release!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1806