Scope new subscription checkout to the active organization - #1095
Scope new subscription checkout to the active organization#1095basriakkaya wants to merge 1 commit into
Conversation
|
@basriakkaya is attempting to deploy a commit to the HackerAI Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
Thank you @basriakkaya — I preserved your commit and attribution in upstream replacement PR #1107, then added the stale-active-organization safeguard and stable recovery code needed before deployment. I’ll close this draft once #1107 has passed preview/CI/CodeRabbit and is merged. |
|
Merged via upstream replacement #1107 as 8c0f0cf, with your contribution credited in the squash commit. Closing this draft as superseded — thank you @basriakkaya. |
Summary
POST /api/subscribeto the authenticated active organizationRoot cause
The new-subscription route ignored the
organizationIdalready returned bygetUserIDAndPro. It listed all active memberships and selecteddata[0], so WorkOS API ordering could choose a different organization than the one active in the application.The selected organization controls the Stripe customer, Checkout metadata, subscription metadata, and eventual entitlement assignment.
Impact
For multi-organization administrators, new Checkout sessions now target the organization selected in the authenticated session. Ambiguous legacy sessions fail safely instead of potentially attaching a paid subscription to the wrong organization.
Validation
pnpm exec jest app/api/subscribe/__tests__/route.test.ts --runInBand --no-watchman— 14 tests passedgit diff --check