Skip to content

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

Open
tomerqodo wants to merge 3 commits into
greptile_full_base_fix_add_server-side_redirect_for_users_with_pending_invites_on_onboarding_page_pr2from
greptile_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 into
greptile_full_base_fix_add_server-side_redirect_for_users_with_pending_invites_on_onboarding_page_pr2from
greptile_full_head_fix_add_server-side_redirect_for_users_with_pending_invites_on_onboarding_page_pr2

Conversation

@tomerqodo
Copy link
Copy Markdown

Benchmark PR from agentic-review-benchmarks#2

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>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

This PR adds server-side redirect logic for users with pending team invites during onboarding. The implementation extracts pending invite checks into a new MembershipRepository.hasPendingInviteByUserId method and adds it to the getting-started onboarding page.

Major changes:

  • Added hasPendingInviteByUserId static method to MembershipRepository
  • Refactored onboardingUtils.ts to use the new repository method instead of direct Prisma queries
  • Added server-side redirect in onboarding page to send users with pending invites to personal settings
  • Added comprehensive integration tests for the new method

Critical issue:

  • The hasPendingInviteByUserId method contains inverted logic - it queries for accepted: true instead of accepted: false, which means it will return the opposite of what's intended. This breaks the entire feature and will cause users WITH accepted memberships to be redirected, while users with actual pending invites will NOT be redirected.

Confidence Score: 0/5

  • This PR has a critical logic bug that inverts the entire feature's behavior
  • The hasPendingInviteByUserId method in MembershipRepository.ts:588 queries for accepted: true when it should query for accepted: false. This completely breaks the intended functionality - users with accepted memberships will be redirected when they shouldn't be, and users with actual pending invites won't be redirected when they should be. The tests expect the correct behavior but the implementation does the opposite.
  • packages/features/membership/repositories/MembershipRepository.ts requires immediate fix to line 588 before merge

Important Files Changed

Filename Overview
packages/features/membership/repositories/MembershipRepository.ts Added hasPendingInviteByUserId method with critical logic bug - queries for accepted: true instead of accepted: false, inverting the intended behavior
packages/features/auth/lib/onboardingUtils.ts Refactored to use new repository method, replaced direct Prisma query with MembershipRepository.hasPendingInviteByUserId, minor formatting changes
apps/web/app/(use-page-wrapper)/onboarding/getting-started/page.tsx Added server-side redirect for users with pending invites, imports reorganized, quote style changed from double to single quotes

Sequence Diagram

sequenceDiagram
    participant User
    participant OnboardingPage as Onboarding Page
    participant Session as getServerSession
    participant MembershipRepo as MembershipRepository
    participant Database as Prisma DB
    
    User->>OnboardingPage: Navigate to /onboarding/getting-started
    OnboardingPage->>Session: getServerSession()
    Session-->>OnboardingPage: session data
    
    alt No session or user ID
        OnboardingPage->>User: redirect(/auth/login)
    else Has session
        OnboardingPage->>MembershipRepo: hasPendingInviteByUserId(userId)
        MembershipRepo->>Database: findFirst(userId, accepted: true)
        Note over MembershipRepo,Database: BUG: Should query accepted: false
        Database-->>MembershipRepo: membership or null
        MembershipRepo-->>OnboardingPage: boolean result
        
        alt Has pending invite
            OnboardingPage->>User: redirect(/onboarding/personal/settings)
        else No pending invite
            OnboardingPage->>User: render OnboardingView
        end
    end
Loading

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

const pendingInvite = await prisma.membership.findFirst({
where: {
userId,
accepted: true,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

inverted logic - checks accepted: true but should check accepted: false for pending invites

Suggested change
accepted: true,
accepted: false,
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/features/membership/repositories/MembershipRepository.ts
Line: 588:588

Comment:
inverted logic - checks `accepted: true` but should check `accepted: false` for pending invites

```suggestion
        accepted: false,
```

How can I resolve this? If you propose a fix, please make it concise.

return redirect("/onboarding/personal/settings");
}

const userEmail = session.user.email || '';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

quote style changed from double to single - inconsistent with rest of codebase formatting

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/app/(use-page-wrapper)/onboarding/getting-started/page.tsx
Line: 35:35

Comment:
quote style changed from double to single - inconsistent with rest of codebase formatting

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

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