[PR #7197] [CLOSED] fix(org): return empty array instead of throwing in listOrganizations #24037

Closed
opened 2026-04-15 22:08:29 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7197
Author: @GautamBytes
Created: 1/8/2026
Status: Closed

Base: canaryHead: fix/list-organizations-unauth-handling


📝 Commits (1)

  • 66f48e0 fix(org): return empty array when unauthenticated

📊 Changes

1 file changed (+6 additions, -4 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/routes/crud-org.ts (+6 -4)

📄 Description

Modifies listOrganizations to return an empty array [] instead of throwing a 401 APIError when the user is unauthenticated.

Changes:

  • Removed strict orgSessionMiddleware from the route.
  • Added manual session check in the handler to return [] if no session exists.

Reasoning:
Fixes DX issues in Server Components (like RootLayout) where an unauthenticated state caused crashes instead of graceful empty states.

Closes #7178


Summary by cubic

Return an empty array from listOrganizations when unauthenticated instead of throwing 401, so server components render a graceful empty state and don’t crash. Addresses Linear #7178.

  • Bug Fixes
    • Removed orgSessionMiddleware from /organization/list.
    • Added a manual session check with getSessionFromCtx; return [] if no session, otherwise fetch using session.user.id.

Written for commit 66f48e03ad. 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/7197 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 1/8/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/list-organizations-unauth-handling` --- ### 📝 Commits (1) - [`66f48e0`](https://github.com/better-auth/better-auth/commit/66f48e03ad7a733a67668b899702291d4d98319c) fix(org): return empty array when unauthenticated ### 📊 Changes **1 file changed** (+6 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/routes/crud-org.ts` (+6 -4) </details> ### 📄 Description Modifies `listOrganizations` to return an empty array `[]` instead of throwing a `401 APIError` when the user is unauthenticated. **Changes:** - Removed strict `orgSessionMiddleware` from the route. - Added manual session check in the handler to return `[]` if no session exists. **Reasoning:** Fixes DX issues in Server Components (like RootLayout) where an unauthenticated state caused crashes instead of graceful empty states. Closes #7178 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Return an empty array from listOrganizations when unauthenticated instead of throwing 401, so server components render a graceful empty state and don’t crash. Addresses Linear #7178. - **Bug Fixes** - Removed orgSessionMiddleware from /organization/list. - Added a manual session check with getSessionFromCtx; return [] if no session, otherwise fetch using session.user.id. <sup>Written for commit 66f48e03ad7a733a67668b899702291d4d98319c. 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-15 22:08:30 -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#24037