Skip to content

fix: Handle pending invitations in auto-add domain users feature#829

Merged
bokelley merged 1 commit into
mainfrom
bokelley/auto-add-members-fix
Jan 20, 2026
Merged

fix: Handle pending invitations in auto-add domain users feature#829
bokelley merged 1 commit into
mainfrom
bokelley/auto-add-members-fix

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

  • Fixed auto-add domain users feature showing users as "can be added" when they have pending invitations
  • Fixed WorkOS error code checking (was checking error message strings instead of error codes)

Root Cause

WorkOS's listOrganizationMemberships only returns active memberships, not pending invitations. When the backfill tried to add users with pending invitations, WorkOS returned cannot_reactivate_pending_organization_membership error, which was being counted as an error instead of a skip.

Changes

  • Status endpoint: Now checks pending invitations and excludes those users from the "can be added" list
  • Backfill endpoint: Handles both organization_membership_already_exists and cannot_reactivate_pending_organization_membership as skip conditions
  • organizations.ts: Fixed error code checking pattern in 3 places (was checking errorMessage.includes() instead of err?.code)

Test plan

  • Build passes
  • All 241 tests pass
  • Verified UI loads correctly on local dev server
  • Code review completed - no critical issues

🤖 Generated with Claude Code

The auto-add domain users backfill was showing users as "can be added"
when they actually had pending invitations that hadn't been accepted yet.

Root cause: WorkOS's listOrganizationMemberships only returns active
memberships, not pending invitations. When trying to add these users,
WorkOS returns error code "cannot_reactivate_pending_organization_membership".

Changes:
- Status endpoint now checks pending invitations and excludes those users
- Backfill endpoint handles both "organization_membership_already_exists"
  and "cannot_reactivate_pending_organization_membership" as skip conditions
- Fixed error code checking in organizations.ts endpoints (was checking
  error message strings instead of error codes)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bokelley bokelley merged commit 2a8106e into main Jan 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant