fix: prevent cancellations if the org has multiple members#3099
fix: prevent cancellations if the org has multiple members#3099
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
📝 WalkthroughWalkthroughThe changes update the cancellation process for subscriptions. The cancelSubscription procedure now validates the organization’s member list by retrieving it via the Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant TS as cancelSubscription Procedure
participant Auth as Auth Module
participant Stripe as Stripe Service
Client->>TS: Request subscription cancellation
TS->>Auth: getOrganizationMemberList(ctx.workspace.orgId)
alt Retrieval Error
Auth-->>TS: Error
TS-->>Client: Send TRPCError("INTERNAL_SERVER_ERROR")
else Retrieval OK
Auth-->>TS: Member List
alt More than one member
TS-->>Client: Send TRPCError("PRECONDITION_FAILED")
else Single member
TS->>Stripe: Proceed with cancellation
Stripe-->>TS: Confirmation
TS-->>Client: Success response
end
end
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Thank you for following the naming conventions for pull request titles! 🙏 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/dashboard/lib/trpc/routers/stripe/cancelSubscription.ts (1)
22-28: Effectively prevents subscription cancellations for multi-member organizations.This validation logic successfully implements the PR objective of preventing subscription cancellations when an organization has multiple members. The error message is clear and instructive, explaining that other members must be removed before downgrading to the free tier.
You might consider adding a small defensive check to ensure
memberships.dataexists before accessing its length property:- if (memberships.data.length > 1) { + if (memberships.data?.length > 1) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/dashboard/lib/trpc/routers/stripe/cancelSubscription.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (17)
- GitHub Check: Test Go API Local / Test (Shard 8/8)
- GitHub Check: Test Go API Local / Test (Shard 5/8)
- GitHub Check: Test Go API Local / Test (Shard 1/8)
- GitHub Check: Test Packages / Test ./internal/resend
- GitHub Check: Test Packages / Test ./apps/dashboard
- GitHub Check: Test Packages / Test ./packages/hono
- GitHub Check: Test Packages / Test ./packages/cache
- GitHub Check: Test Packages / Test ./packages/api
- GitHub Check: Test Packages / Test ./internal/encryption
- GitHub Check: Test Packages / Test ./internal/billing
- GitHub Check: Test Packages / Test ./internal/id
- GitHub Check: Test Packages / Test ./internal/hash
- GitHub Check: Test API / API Test Local
- GitHub Check: Build / Build
- GitHub Check: Test Agent Local / test_agent_local
- GitHub Check: autofix
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
apps/dashboard/lib/trpc/routers/stripe/cancelSubscription.ts (2)
1-1: Import for organization member validation added correctly.The auth module import is appropriately added to enable the new organization membership check functionality.
15-21: Good error handling for organization member retrieval.The implementation correctly retrieves the organization's member list and handles potential errors appropriately. The error is logged for debugging purposes and translated into a meaningful TRPC error with a clear message for the client.
|
The tRPC error is enough no? |
|
Summary by CodeRabbit