Skip to content

fix: add server-side redirect for users with pending invites on onboarding page#2

Open
tomerqodo wants to merge 3 commits intocoderabbit_full_base_fix_add_server-side_redirect_for_users_with_pending_invites_on_onboarding_page_pr2from
coderabbit_full_head_fix_add_server-side_redirect_for_users_with_pending_invites_on_onboarding_page_pr2
Open

fix: add server-side redirect for users with pending invites on onboarding page#2
tomerqodo wants to merge 3 commits intocoderabbit_full_base_fix_add_server-side_redirect_for_users_with_pending_invites_on_onboarding_page_pr2from
coderabbit_full_head_fix_add_server-side_redirect_for_users_with_pending_invites_on_onboarding_page_pr2

Conversation

@tomerqodo
Copy link

@tomerqodo tomerqodo commented Jan 29, 2026

Benchmark PR from agentic-review-benchmarks#2

Summary by CodeRabbit

  • New Features

    • Added pending team invite detection during the onboarding flow to redirect users with outstanding invitations.
  • Improvements

    • Enhanced onboarding logic to account for pending invites in the decision path.
  • Tests

    • Added comprehensive integration tests for pending invite detection with multiple scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

devin-ai-integration bot and others added 3 commits January 25, 2026 12:01
…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>
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

The PR introduces a pending membership invite check in the onboarding flow by adding a new MembershipRepository.hasPendingInviteByUserId() method, integrating it into onboarding logic, and adding comprehensive integration tests to validate the behavior.

Changes

Cohort / File(s) Summary
Onboarding Flow Integration
apps/web/app/(use-page-wrapper)/onboarding/getting-started/page.tsx, packages/features/auth/lib/onboardingUtils.ts
Added pre-redirect logic to check for pending membership invites using the new repository method. Users with pending invites are redirected to settings. Control flow updated to account for pending invites in onboarding decision paths.
Membership Repository
packages/features/membership/repositories/MembershipRepository.ts
Added new static method hasPendingInviteByUserId() to query pending invites by user ID. Normalized imports into type-only blocks. Simplified existing hasAcceptedMembershipByEmail() method signature formatting.
Integration Tests
packages/features/membership/repositories/MembershipRepository.integration-test.ts
New test file with comprehensive integration tests for hasPendingInviteByUserId(). Includes setup/teardown logic for test teams and memberships, with four test cases validating pending invite detection across different user scenarios.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant OnboardingPage as Onboarding Page
    participant OnboardingUtils as Onboarding Utils
    participant MembershipRepo as Membership Repository
    participant Database as Database

    User->>OnboardingPage: Request /getting-started
    OnboardingPage->>OnboardingPage: Check session user ID
    
    alt Session exists
        OnboardingPage->>MembershipRepo: hasPendingInviteByUserId(userId)
        MembershipRepo->>Database: Query pending invite (accepted: false)
        Database-->>MembershipRepo: Result
        MembershipRepo-->>OnboardingPage: boolean
        
        alt Has pending invite
            OnboardingPage-->>User: Redirect to /onboarding/personal/settings
        else No pending invite
            OnboardingPage->>OnboardingUtils: getOnboardingRedirectPath()
            OnboardingUtils->>Database: Check feature flags & invites
            Database-->>OnboardingUtils: Results
            OnboardingUtils-->>OnboardingPage: Redirect path
            OnboardingPage-->>User: Redirect to destination
        end
    else No session
        OnboardingPage-->>User: Redirect to /login
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hops through invites, pending and true,
The repository checks what users will do,
Before onboarding paths diverge and spread,
A gentle redirect sends them ahead! 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: add server-side redirect for users with pending invites on onboarding page' clearly and specifically summarizes the main change: adding a server-side redirect for users with pending invites on the onboarding page.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/features/auth/lib/onboardingUtils.ts (1)

67-73: Onboarding V3 users are always redirected to personal settings.

hasPendingInvite || onboardingV3Enabled makes the “getting-started” path unreachable whenever V3 is enabled, which looks unintended per the PR goal (only pending invites should skip plan selection).

✅ Suggested fix
-  if (hasPendingInvite || onboardingV3Enabled) {
-    return "/onboarding/personal/settings";
-  }
-
-  return onboardingV3Enabled ? "/onboarding/getting-started" : "/getting-started";
+  if (hasPendingInvite) {
+    return "/onboarding/personal/settings";
+  }
+
+  return onboardingV3Enabled ? "/onboarding/getting-started" : "/getting-started";
🤖 Fix all issues with AI agents
In `@packages/features/membership/repositories/MembershipRepository.ts`:
- Around line 584-589: The hasPendingInviteByUserId method is incorrectly
filtering for accepted: true so it matches accepted memberships instead of
pending invites; update the prisma.membership.findFirst query inside
hasPendingInviteByUserId to filter for pending invites (e.g., accepted: false or
the appropriate null/false value used elsewhere for pending) so the method
returns true only when an invite is actually pending.

Comment on lines +584 to +589
static async hasPendingInviteByUserId({ userId }: { userId: number }): Promise<boolean> {
const pendingInvite = await prisma.membership.findFirst({
where: {
userId,
accepted: true,
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Pending-invite lookup is filtering accepted memberships.

This method will return true for already-accepted memberships and false for actual pending invites, which breaks the redirect behavior and the new tests.

✅ Suggested fix
-  const pendingInvite = await prisma.membership.findFirst({
-    where: {
-      userId,
-      accepted: true,
-    },
-    select: {
-      id: true,
-    },
-  });
+  const pendingInvite = await prisma.membership.findFirst({
+    where: {
+      userId,
+      accepted: false,
+    },
+    select: {
+      id: true,
+    },
+  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static async hasPendingInviteByUserId({ userId }: { userId: number }): Promise<boolean> {
const pendingInvite = await prisma.membership.findFirst({
where: {
userId,
accepted: true,
},
static async hasPendingInviteByUserId({ userId }: { userId: number }): Promise<boolean> {
const pendingInvite = await prisma.membership.findFirst({
where: {
userId,
accepted: false,
},
select: {
id: true,
},
});
🤖 Prompt for AI Agents
In `@packages/features/membership/repositories/MembershipRepository.ts` around
lines 584 - 589, The hasPendingInviteByUserId method is incorrectly filtering
for accepted: true so it matches accepted memberships instead of pending
invites; update the prisma.membership.findFirst query inside
hasPendingInviteByUserId to filter for pending invites (e.g., accepted: false or
the appropriate null/false value used elsewhere for pending) so the method
returns true only when an invite is actually pending.

@hussam789
Copy link

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

2 participants