Code Review Bench PR #26829 - fix: add server-side redirect for users with pending invites on onboarding page#2
Conversation
…rding page When users sign up with an invite token, they were being redirected to /onboarding/getting-started (plan selection page) instead of going directly to /onboarding/personal/settings. This caused users to see the payment prompt for team/org plans before being redirected. This fix adds a server-side check in the /onboarding/getting-started page to redirect users with pending invites directly to the personal onboarding flow, preventing them from seeing the plan selection page. Also refactored onboardingUtils.ts to use MembershipRepository instead of direct prisma access. Co-Authored-By: sean@cal.com <Sean@brydon.io>
Co-Authored-By: sean@cal.com <Sean@brydon.io>
| const pendingInvite = await prisma.membership.findFirst({ | ||
| where: { | ||
| userId, | ||
| accepted: true, |
There was a problem hiding this comment.
🚨 Bug: hasPendingInviteByUserId queries accepted: true instead of false
The new hasPendingInviteByUserId method is supposed to check if a user has pending (unaccepted) invites, but the Prisma query filters for accepted: true instead of accepted: false. This means the method returns true when a user has accepted memberships and false when they actually have pending invites — the exact opposite of the intended behavior.
Impact: Users with pending team invites will NOT be redirected to the personal onboarding page (the entire point of this PR). Users who have already accepted team memberships WILL be incorrectly redirected away from the getting-started page. This completely inverts the business logic.
The original code in onboardingUtils.ts (before this PR) correctly queried accepted: false. The refactoring introduced this inversion.
Was this helpful? React with 👍 / 👎
| accepted: true, | |
| const pendingInvite = await prisma.membership.findFirst({ | |
| where: { | |
| userId, | |
| accepted: false, | |
| }, | |
| select: { | |
| id: true, | |
| }, | |
| }); |
- Apply suggested fix
| const hasPendingInvite = await MembershipRepository.hasPendingInviteByUserId({ userId }); | ||
|
|
||
| if (pendingInvite && onboardingV3Enabled) { | ||
| if (hasPendingInvite || onboardingV3Enabled) { |
There was a problem hiding this comment.
🚨 Bug: Logic changed from && to ||, breaking onboarding redirect
The original condition was if (pendingInvite && onboardingV3Enabled) — meaning users are redirected to personal onboarding only when they have a pending invite AND onboarding-v3 is enabled. The refactored code changes this to if (hasPendingInvite || onboardingV3Enabled), which means:
- All users with
onboardingV3Enabledwill be redirected to/onboarding/personal/settingsregardless of invite status, bypassing the getting-started flow entirely. - Users with pending invites will be redirected even when onboarding-v3 is disabled.
- Line 73 is now dead code:
return onboardingV3Enabled ? "/onboarding/getting-started" : "/getting-started"can never evaluateonboardingV3Enabledastruebecause that case is already caught by the||condition on line 69.
This is a significant behavioral regression that changes the onboarding flow for all users, not just those with pending invites.
Was this helpful? React with 👍 / 👎
| if (hasPendingInvite || onboardingV3Enabled) { | |
| if (hasPendingInvite && onboardingV3Enabled) { |
- Apply suggested fix
| }); | ||
| createdMembershipIds.push(acceptedMembership.id); | ||
|
|
||
| if (team2) { |
There was a problem hiding this comment.
⚠️ Bug: Test silently passes without validating core behavior
The "mixed invites" test at line 119 wraps the pending membership creation in if (team2) and then asserts expect(result).toBe(team2 ? true : false). If no second team exists in the database, the test never creates a pending invite and simply asserts false — making it a duplicate of the "no pending invites" test.
This means the test can pass in environments where only one team exists without ever testing the "both accepted and pending invites" scenario. A test that silently degrades to testing a different scenario undermines confidence in the test suite.
The test should either:
- Create a second team explicitly (like
beforeAlldoes for the first team), or - Fail explicitly if the required precondition (
team2exists) is not met.
Was this helpful? React with 👍 / 👎
- Apply suggested fix
There was a problem hiding this comment.
Configure merge blocking · Maintainers can dismiss this review. Gitar never approves changes.
Code Review 🚫 Blocked 0 resolved / 3 findingsTwo critical logic bugs: the 🚨 Bug:
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
Benchmark Evaluation ResultsGround Truth Bugs (Recall: 3/4 = 75.0%)
Extra Gitar Findings
Summary
|
Code Review Bench PR calcom#26829 - fix: add server-side redirect for users with pending invites on onboarding page
Benchmark PR for Gitar evaluation
Original PR: agentic-review-benchmarks#2
fix: add server-side redirect for users with pending invites on onboarding page
Summary by Gitar
This PR fixes a UX issue where users signing up with team invite tokens were unnecessarily shown payment prompts during onboarding:
/onboarding/getting-startedpage to detect users with pending team invites and redirect them directly to personal onboarding settings, skipping the plan selection pagehasPendingInviteByUserId()as a static method inMembershipRepositoryto check for unaccepted memberships, replacing direct Prisma queries