( userId: string, referenceId: string, action?: string )
| 18 | * - Personal subscriptions skip this check to allow upgrades. |
| 19 | */ |
| 20 | export async function authorizeSubscriptionReference( |
| 21 | userId: string, |
| 22 | referenceId: string, |
| 23 | action?: string |
| 24 | ): Promise<boolean> { |
| 25 | if (!isOrgScopedSubscription({ referenceId }, userId)) { |
| 26 | return true |
| 27 | } |
| 28 | |
| 29 | if (action === 'upgrade-subscription' && (await hasPaidSubscription(referenceId))) { |
| 30 | logger.warn('Blocking checkout - active subscription already exists for organization', { |
| 31 | userId, |
| 32 | referenceId, |
| 33 | }) |
| 34 | return false |
| 35 | } |
| 36 | |
| 37 | return isOrganizationOwnerOrAdmin(userId, referenceId) |
| 38 | } |
no test coverage detected