[PR #7024] feat(org): allow passing userId to listUserTeams API #7030

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7024
Author: @GautamBytes
Created: 12/27/2025
Status: 🔄 Open

Base: canaryHead: feat/list-user-teams-userid


📝 Commits (3)

  • 3c936bb feat(org): allow passing userId to listUserTeams API
  • 6f01ee5 fix typecheck
  • e5bc5ed updated doc and added tests

📊 Changes

4 files changed (+237 additions, -4 deletions)

View changed files

📝 docs/content/docs/plugins/organization.mdx (+4 -0)
📝 packages/better-auth/src/plugins/organization/client.ts (+10 -0)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+142 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-team.ts (+81 -4)

📄 Description

Description

Closes #7012

This PR updates the listUserTeams endpoint in the Organization plugin to support passing an optional userId. This allows admins to view the teams of a specific member, which is required for Admin UI implementations.

Changes

  • Server (crud-team.ts): - Updated listUserTeams schema to accept userId.
    • Added logic to fetch teams for the target user instead of always the session user.
  • Client (client.ts): - Updated the client SDK to accept { userId?: string } for better type safety.
  • Tests (team.test.ts): - Added comprehensive test cases covering self-query, admin-query, unauthorized access, and cross-organization privacy checks.

Summary by cubic

Adds optional userId support to /organization/list-user-teams so admins can view a specific member’s teams. Enforces permissions and privacy, and updates the client SDK.

  • New Features
    • API: GET /organization/list-user-teams accepts ?userId; defaults to the session user.
    • Security: Non-self queries require member:read; requires an active org; validates the target user is a member; filters results to the active org.
    • Client: Added organizationClient.teams.listUserTeams({ query: { userId? } }).

Written for commit e5bc5edd4f. 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/7024 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 12/27/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `feat/list-user-teams-userid` --- ### 📝 Commits (3) - [`3c936bb`](https://github.com/better-auth/better-auth/commit/3c936bbf8e867ba9d7db454e2e141a29ac23cf61) feat(org): allow passing userId to listUserTeams API - [`6f01ee5`](https://github.com/better-auth/better-auth/commit/6f01ee58e34db028dd26d9f368bbb5b29444b376) fix typecheck - [`e5bc5ed`](https://github.com/better-auth/better-auth/commit/e5bc5edd4f038cc4a994b7396d7c782112c26afb) updated doc and added tests ### 📊 Changes **4 files changed** (+237 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/organization.mdx` (+4 -0) 📝 `packages/better-auth/src/plugins/organization/client.ts` (+10 -0) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+142 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-team.ts` (+81 -4) </details> ### 📄 Description ## Description Closes #7012 This PR updates the `listUserTeams` endpoint in the Organization plugin to support passing an optional `userId`. This allows admins to view the teams of a specific member, which is required for Admin UI implementations. ## Changes - **Server (`crud-team.ts`):** - Updated `listUserTeams` schema to accept `userId`. - Added logic to fetch teams for the target user instead of always the session user. - **Client (`client.ts`):** - Updated the client SDK to accept `{ userId?: string }` for better type safety. - **Tests (`team.test.ts`):** - Added comprehensive test cases covering self-query, admin-query, unauthorized access, and cross-organization privacy checks. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds optional userId support to /organization/list-user-teams so admins can view a specific member’s teams. Enforces permissions and privacy, and updates the client SDK. - **New Features** - API: GET /organization/list-user-teams accepts ?userId; defaults to the session user. - Security: Non-self queries require member:read; requires an active org; validates the target user is a member; filters results to the active org. - Client: Added organizationClient.teams.listUserTeams({ query: { userId? } }). <sup>Written for commit e5bc5edd4f038cc4a994b7396d7c782112c26afb. 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:21:49 -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#7030