[PR #3520] [MERGED] fix: resend invitation should reuse existing invitation instead of creating duplicate #4866

Closed
opened 2026-03-13 12:02:30 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3520
Author: @gingeekrishna
Created: 7/21/2025
Status: Merged
Merged: 8/17/2025
Merged by: @Bekacru

Base: canaryHead: fix-resend-invite-reuse-existing-3507


📝 Commits (10+)

  • 39742cd fix: resend invitation should reuse existing invitation instead of creating duplicate
  • db8d36d lint
  • e3f446d typecheck
  • 9ace8e8 Merge branch 'main' into fix-resend-invite-reuse-existing-3507
  • fd63e3c Merge branch 'main' into fix-resend-invite-reuse-existing-3507
  • c74c44d chore: add changeset for resend invitation fix
  • f4d9468 Merge branch 'main' into fix-resend-invite-reuse-existing-3507
  • 97f9529 fix: update invitation expiration on resend and simplify changeset
  • cac8072 Merge latest changes from remote
  • b7457e5 Merge branch 'main' into fix-resend-invite-reuse-existing-3507

📊 Changes

2 files changed (+128 additions, -7 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/organization.test.ts (+68 -0)
📝 packages/better-auth/src/plugins/organization/routes/crud-invites.ts (+60 -7)

📄 Description

resend invitation should reuse existing invitation instead of creating duplicate

  • Modified inviteMember to reuse existing pending invitations when resend=true
  • Added logic to return existing invitation instead of creating new one
  • Moved organization lookup earlier in the flow for proper access
  • Added comprehensive test to verify resend behavior reuses same invitation ID
  • Prevents duplicate invitation records in database when resending
  • Fixes issue #3507 where resend was creating duplicates instead of being idempotent

The fix ensures that calling organization.inviteMember with resend=true:

  1. Finds existing pending invitation for the email
  2. Sends invitation email again using existing invitation data
  3. Returns the same invitation object (same ID)
  4. Does not create duplicate invitation records

Summary by cubic

Resending an organization invitation now reuses the existing pending invitation instead of creating a duplicate, fixing issue #3507.

  • Bug Fixes
    • When resend=true, inviteMember finds and returns the existing invitation and sends the email again.
    • Prevents duplicate invitation records in the database.
    • Added a test to confirm the same invitation ID is reused.

🔄 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/3520 **Author:** [@gingeekrishna](https://github.com/gingeekrishna) **Created:** 7/21/2025 **Status:** ✅ Merged **Merged:** 8/17/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix-resend-invite-reuse-existing-3507` --- ### 📝 Commits (10+) - [`39742cd`](https://github.com/better-auth/better-auth/commit/39742cd896d8a98791c3577c60cced92fc43f201) fix: resend invitation should reuse existing invitation instead of creating duplicate - [`db8d36d`](https://github.com/better-auth/better-auth/commit/db8d36ddda12ff6f66f5fc4592d9b7ca5bccfbe0) lint - [`e3f446d`](https://github.com/better-auth/better-auth/commit/e3f446d00e874cf1f3cd7a380134e9806bc40a76) typecheck - [`9ace8e8`](https://github.com/better-auth/better-auth/commit/9ace8e8854600136b29d3b7f399a64cf88aec3cb) Merge branch 'main' into fix-resend-invite-reuse-existing-3507 - [`fd63e3c`](https://github.com/better-auth/better-auth/commit/fd63e3c5ba694a7fab47e0c20222c18ad6b473b7) Merge branch 'main' into fix-resend-invite-reuse-existing-3507 - [`c74c44d`](https://github.com/better-auth/better-auth/commit/c74c44d18e7ac7a1368b1398b7d540df97391efc) chore: add changeset for resend invitation fix - [`f4d9468`](https://github.com/better-auth/better-auth/commit/f4d94683a1da7aae52ccc409ab42e15dc8d399c6) Merge branch 'main' into fix-resend-invite-reuse-existing-3507 - [`97f9529`](https://github.com/better-auth/better-auth/commit/97f9529cc40ee699e71d30d83254f82f14d8dcaa) fix: update invitation expiration on resend and simplify changeset - [`cac8072`](https://github.com/better-auth/better-auth/commit/cac8072ecbeec6f2bef8710d1d25cd639315597a) Merge latest changes from remote - [`b7457e5`](https://github.com/better-auth/better-auth/commit/b7457e50f672ad037899034d16ec11f874bd98a5) Merge branch 'main' into fix-resend-invite-reuse-existing-3507 ### 📊 Changes **2 files changed** (+128 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/organization.test.ts` (+68 -0) 📝 `packages/better-auth/src/plugins/organization/routes/crud-invites.ts` (+60 -7) </details> ### 📄 Description resend invitation should reuse existing invitation instead of creating duplicate - Modified inviteMember to reuse existing pending invitations when resend=true - Added logic to return existing invitation instead of creating new one - Moved organization lookup earlier in the flow for proper access - Added comprehensive test to verify resend behavior reuses same invitation ID - Prevents duplicate invitation records in database when resending - Fixes issue #3507 where resend was creating duplicates instead of being idempotent The fix ensures that calling organization.inviteMember with resend=true: 1. Finds existing pending invitation for the email 2. Sends invitation email again using existing invitation data 3. Returns the same invitation object (same ID) 4. Does not create duplicate invitation records <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Resending an organization invitation now reuses the existing pending invitation instead of creating a duplicate, fixing issue #3507. - **Bug Fixes** - When resend=true, inviteMember finds and returns the existing invitation and sends the email again. - Prevents duplicate invitation records in the database. - Added a test to confirm the same invitation ID is reused. <!-- 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 12:02: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#4866