[PR #8694] [MERGED] fix(organization): filter null organizations in listUserInvitations #25051

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8694
Author: @raihanbrillmark
Created: 3/19/2026
Status: Merged
Merged: 3/19/2026
Merged by: @himself65

Base: canaryHead: fix/list-user-invitations-crashes


📝 Commits (1)

  • 6b52652 fix(organization): filter null organizations in listUserInvitations

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/adapter.ts (+2 -2)

📄 Description

Summary

  • Fixed a crash in listUserInvitations caused by invitations whose associated organization has been deleted (or is otherwise missing from a join result).
  • Added .filter(Boolean) to skip null/undefined entries before mapping.
  • Used optional chaining (organization?.name) to safely access the organization name.

Background

When listUserInvitations performs a joined query over the invitation model, it's possible for the resolved organization to be null — for example, if the organization was deleted after the invitation was created but before the invitations were listed. Previously this caused an uncaught runtime crash when destructuring { organization, ...inv } and then accessing organization.name on a null value.

Changes

packages/better-auth/src/plugins/organization/adapter.ts

  • listUserInvitations: added .filter(Boolean) before .map(...) to drop null entries returned from the join.
  • Changed organization.nameorganization?.name to safely handle any null organization that slips through.

Breaking Changes

None.

Deprecations

None.

Screenshots

N/A — no UI changes.

Fixes a runtime crash in the organization plugin when listing invitations for a user whose invitation's organization no longer exists.

Issue: https://github.com/better-auth/better-auth/issues/8691

Summary by cubic

Prevented crashes in listUserInvitations when an invitation’s organization is null. We now filter out falsy invitations and safely read the organization name with optional chaining.

Written for commit 6b52652fb1. 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/8694 **Author:** [@raihanbrillmark](https://github.com/raihanbrillmark) **Created:** 3/19/2026 **Status:** ✅ Merged **Merged:** 3/19/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/list-user-invitations-crashes` --- ### 📝 Commits (1) - [`6b52652`](https://github.com/better-auth/better-auth/commit/6b52652fb121f73d6e0d91eb62bd90d2102f92ad) fix(organization): filter null organizations in listUserInvitations ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+2 -2) </details> ### 📄 Description ## Summary - Fixed a crash in `listUserInvitations` caused by invitations whose associated organization has been deleted (or is otherwise missing from a join result). - Added `.filter(Boolean)` to skip null/undefined entries before mapping. - Used optional chaining (`organization?.name`) to safely access the organization name. ## Background When `listUserInvitations` performs a joined query over the `invitation` model, it's possible for the resolved `organization` to be `null` — for example, if the organization was deleted after the invitation was created but before the invitations were listed. Previously this caused an uncaught runtime crash when destructuring `{ organization, ...inv }` and then accessing `organization.name` on a null value. ## Changes **`packages/better-auth/src/plugins/organization/adapter.ts`** - `listUserInvitations`: added `.filter(Boolean)` before `.map(...)` to drop null entries returned from the join. - Changed `organization.name` → `organization?.name` to safely handle any null organization that slips through. ## Breaking Changes None. ## Deprecations None. ## Screenshots N/A — no UI changes. ## Related Issues Fixes a runtime crash in the organization plugin when listing invitations for a user whose invitation's organization no longer exists. Issue: https://github.com/better-auth/better-auth/issues/8691 <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Prevented crashes in `listUserInvitations` when an invitation’s organization is null. We now filter out falsy invitations and safely read the organization name with optional chaining. <sup>Written for commit 6b52652fb121f73d6e0d91eb62bd90d2102f92ad. 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:42:25 -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#25051