fix(billing): an organization token already names its organization

Creating a product with one sends `organization_id` alongside a token that
implies it, which is refused outright rather than ignored — so which kind of
token is in hand has to be known before the call, not after. A personal token
can see several organizations and still has to say which.
This commit is contained in:
Wanjohi
2026-09-19 00:59:36 +03:00
parent 757ff79233
commit b01d8eabb3

View File

@@ -54,6 +54,15 @@ if (!accessToken) {
const polar = new Polar({ accessToken, server });
/**
* An organization token already names its organization.
*
* Sending `organizationId` alongside one is refused outright rather than
* ignored, so which kind of token this is has to be known before the call. A
* personal token can see several organizations and must say which.
*/
const scopedToOrganization = accessToken.startsWith('polar_oat_');
const organizations = await polar.organizations.listOrganizations({ limit: 2 });
const organization = organizations.result.items.at(0);
if (!organization) {
@@ -89,7 +98,7 @@ if (!apply) {
}
const created = await polar.products.create({
organizationId: organization.id,
...(scopedToOrganization ? {} : { organizationId: organization.id }),
name: PRODUCT.name,
description: PRODUCT.description,
recurringInterval: PRODUCT.recurringInterval,