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

Open
opened 2026-04-17 23:23:36 -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: mainHead: feat/list-user-teams-userid


📝 Commits (5)

  • 3c936bb feat(org): allow passing userId to listUserTeams API
  • 6f01ee5 fix typecheck
  • e5bc5ed updated doc and added tests
  • d42c6ee Merge remote-tracking branch 'upstream/main' into feat/list-user-teams-userid
  • 5d0686a fix(org): preserve listUserTeams client fetch options

📊 Changes

4 files changed (+295 additions, -5 deletions)

View changed files

📝 docs/content/docs/plugins/organization.mdx (+5 -1)
📝 packages/better-auth/src/plugins/organization/client.ts (+45 -0)
📝 packages/better-auth/src/plugins/organization/organization.test.ts (+164 -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 'member:update' for non-self queries, scopes results to the active org, and updates the client and docs.

  • New Features

    • API: GET /organization/list-user-teams accepts ?userId; defaults to the session user.
    • Security: Non-self queries require 'member:update'; validates target membership; filters results to the active org.
    • Client: Added organizationClient.teams.listUserTeams with query: { userId? }.
  • Bug Fixes

    • Client: Preserves fetchOptions in listUserTeams and supports both (query, fetchOptions) and ({ query, fetchOptions }) call shapes.

Written for commit 5d0686a8c9. 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:** `main` ← **Head:** `feat/list-user-teams-userid` --- ### 📝 Commits (5) - [`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 - [`d42c6ee`](https://github.com/better-auth/better-auth/commit/d42c6ee8b5690401319140ab1363250a59db97aa) Merge remote-tracking branch 'upstream/main' into feat/list-user-teams-userid - [`5d0686a`](https://github.com/better-auth/better-auth/commit/5d0686a8c9ba9045fa6a773fab312916a64479a7) fix(org): preserve listUserTeams client fetch options ### 📊 Changes **4 files changed** (+295 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/organization.mdx` (+5 -1) 📝 `packages/better-auth/src/plugins/organization/client.ts` (+45 -0) 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+164 -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 'member:update' for non-self queries, scopes results to the active org, and updates the client and docs. - **New Features** - API: GET /organization/list-user-teams accepts ?userId; defaults to the session user. - Security: Non-self queries require 'member:update'; validates target membership; filters results to the active org. - Client: Added `organizationClient.teams.listUserTeams` with `query: { userId? }`. - **Bug Fixes** - Client: Preserves `fetchOptions` in `listUserTeams` and supports both `(query, fetchOptions)` and `({ query, fetchOptions })` call shapes. <sup>Written for commit 5d0686a8c9ba9045fa6a773fab312916a64479a7. 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-04-17 23:23:36 -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#32631