Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

fix upgrade to team plan. when someone upgraded, an org was auto-created and the subscriptions referenceId changed from their user tot hat org, and their usage limits weren't being updated

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Aug 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Building Building Preview Comment Aug 20, 2025 7:27am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Aug 20, 2025 7:27am

@waleedlatif1 waleedlatif1 merged commit 214a035 into staging Aug 20, 2025
3 of 4 checks passed
Copy link
Contributor

@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.

Greptile Summary

This PR fixes a critical bug in the team plan upgrade flow where users weren't receiving their proper usage limits after upgrading. The issue occurred because when a user upgrades to a team plan, the system automatically creates an organization and transfers the subscription's referenceId from the individual user to the organization. This transfer meant that usage limits were only being synced for the organization, not the individual user who made the purchase.

The fix introduces two key changes to the team upgrade flow in apps/sim/lib/auth.ts:

  1. Pre-organization sync: Before creating the organization and changing the subscription's referenceId, the code now stores the original user ID and immediately syncs usage limits for that user with their new team plan. This ensures the purchasing user gets their upgraded limits before the referenceId changes.

  2. Conditional post-sync logic: After organization creation, usage limits are only synced for non-team plans to avoid duplicate operations, since team plan users have already had their limits synced in the previous step.

This change integrates with the existing usage monitoring system (which tracks usage against subscription limits as shown in the usage-monitor.ts context) and ensures that the subscription upgrade process maintains continuity of service for users transitioning from individual to team plans.

Confidence score: 5/5

  • This PR is extremely safe to merge with minimal risk of production issues
  • Score reflects a well-targeted bug fix with clear problem identification and solution implementation
  • No files require special attention as the changes are localized and well-documented

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

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