fix: accepting a redundant invite to an organization the user already belongs to errors out#1742
Open
giladresisi wants to merge 1 commit into
Open
fix: accepting a redundant invite to an organization the user already belongs to errors out#1742giladresisi wants to merge 1 commit into
giladresisi wants to merge 1 commit into
Conversation
… belongs to no longer errors addUserToOrg only deduped on the invite id, never on membership, so a user who was already a member of the organization and clicked another still-valid invite link hit the userId_organizationId unique constraint and the request failed with an uncaught error. Two pre-existing flows trigger it, both involving two separate invites for the same user and ending in that same uncaught error: (1) the second invite is sent before the user joins via the first, and clicked after; (2) the second invite is sent after the user has already joined, and then clicked. Check membership first and return false, the same value joinOrg already handles as a clean no-op. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Contribution-checker quality warning Heuristics that flagged:
If this is a genuine contribution, please add detail to your PR description and tighten the diff scope before reviewers look at it. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When a user who is already a member of an organization clicks another still-valid invite link,
addUserToOrgonly dedupes on the invite id ("has this specific invite already been redeemed?") and never checks membership. The membership create then hits theuserId_organizationIdunique constraint and the request fails with an uncaught error.Two pre-existing flows trigger it, both involving two separate invites for the same user and ending in that same uncaught error:
Membership data stays correct either way — the unique index blocks the duplicate — the bug is the uncaught error instead of a graceful no-op.
What changed
addUserToOrgnow checks for an existinguserOrganizationrow for that user + organization before creating one, and returnsfalse— the same value it already returns for a redeemed invite, which the join flow handles as a clean no-op (the user just lands back in the app).🤖 Generated with Claude Code