[PR #4035] [MERGED] fix(org): prevent fk constraint violation when creating invitation without teams #22049

Closed
opened 2026-04-15 20:46:49 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4035
Author: @Kinfe123
Created: 8/15/2025
Status: Merged
Merged: 8/15/2025
Merged by: @Bekacru

Base: canaryHead: fix/org-teamid-invitation-fk


📝 Commits (2)

  • c6f2d5c fix(org): prevent foreign key constraint violation when creating invitations without teams
  • 386c771 lint

📊 Changes

3 files changed (+21 additions, -3 deletions)

View changed files

📝 packages/better-auth/src/plugins/organization/adapter.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/schema.ts (+1 -1)
📝 packages/better-auth/src/plugins/organization/team.test.ts (+18 -0)

📄 Description

closes #4033


Summary by cubic

Fixes invitation creation when no team is selected by setting teamId to null instead of an empty string. This prevents foreign key constraint errors and keeps invites without teams valid.

  • Bug Fixes
    • Set teamId to null when invitation.teamIds is empty.
    • Updated schema to accept nullish teamId.
    • Added test to ensure invitations can be created without a team and do not use an empty string.

🔄 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/4035 **Author:** [@Kinfe123](https://github.com/Kinfe123) **Created:** 8/15/2025 **Status:** ✅ Merged **Merged:** 8/15/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/org-teamid-invitation-fk` --- ### 📝 Commits (2) - [`c6f2d5c`](https://github.com/better-auth/better-auth/commit/c6f2d5cb54ee2f1129fc88b91c71757b2eb7639c) fix(org): prevent foreign key constraint violation when creating invitations without teams - [`386c771`](https://github.com/better-auth/better-auth/commit/386c771258f36ae26c537bc948af14c5fcbbd674) lint ### 📊 Changes **3 files changed** (+21 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/organization/adapter.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/schema.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/organization/team.test.ts` (+18 -0) </details> ### 📄 Description closes #4033 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes invitation creation when no team is selected by setting teamId to null instead of an empty string. This prevents foreign key constraint errors and keeps invites without teams valid. - Bug Fixes - Set teamId to null when invitation.teamIds is empty. - Updated schema to accept nullish teamId. - Added test to ensure invitations can be created without a team and do not use an empty string. <!-- 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 20:46: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#22049