File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed
Expand file tree Collapse file tree 1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -10,28 +10,28 @@ const logger = createLogger('BillingAuthorization')
1010 * Check if a user is authorized to manage billing for a given reference ID
1111 * Reference ID can be either a user ID (individual subscription) or organization ID (team subscription)
1212 *
13- * This function also performs duplicate subscription validation:
14- * - Rejects if the referenceId already has an active subscription (prevents duplicates)
13+ * This function also performs duplicate subscription validation for organizations:
14+ * - Rejects if an organization already has an active subscription (prevents duplicates)
15+ * - Personal subscriptions (referenceId === userId) skip this check to allow upgrades
1516 */
1617export async function authorizeSubscriptionReference (
1718 userId : string ,
1819 referenceId : string
1920) : Promise < boolean > {
20- // Check for existing active subscriptions on this referenceId
21- // This prevents creating duplicate subscriptions for the same entity
21+ // User can always manage their own subscriptions (Pro upgrades, etc.)
22+ if ( referenceId === userId ) {
23+ return true
24+ }
25+
26+ // For organizations: check for existing active subscriptions to prevent duplicates
2227 if ( await hasActiveSubscription ( referenceId ) ) {
23- logger . warn ( 'Blocking checkout - active subscription already exists for referenceId ' , {
28+ logger . warn ( 'Blocking checkout - active subscription already exists for organization ' , {
2429 userId,
2530 referenceId,
2631 } )
2732 return false
2833 }
2934
30- // User can always manage their own subscriptions
31- if ( referenceId === userId ) {
32- return true
33- }
34-
3535 // Check if referenceId is an organizationId the user has admin rights to
3636 const members = await db
3737 . select ( )
You can’t perform that action at this time.
0 commit comments