FlowiseAI/Flowise · error · Error

Customer ID is required

Error message

Customer ID is required

What it means

createStripeCustomerPortalSession builds a Stripe billing portal session and requires the caller's authenticated user object to carry activeOrganizationCustomerId. The value is read from req.user.activeOrganizationCustomerId; if it's falsy (undefined, null, empty), a generic Error is thrown before any Stripe call. This is a session/auth-state precondition: the user must belong to an organization with a Stripe customer record.

Source

Thrown at packages/server/src/StripeManager.ts:129

            }
        }

        await this.cacheManager.updateSubscriptionDataToCache(subscriptionId, {
            features,
            subsriptionDetails: this.getSubscriptionObject(subscription)
        })

        return features
    }

    public async createStripeCustomerPortalSession(req: Request) {
        if (!this.stripe) {
            throw new Error('Stripe is not initialized')
        }

        const customerId = req.user?.activeOrganizationCustomerId
        if (!customerId) {
            throw new Error('Customer ID is required')
        }

        const subscriptionId = req.user?.activeOrganizationSubscriptionId
        if (!subscriptionId) {
            throw new Error('Subscription ID is required')
        }

        try {
            const prodPriceIds = await this.getPriceIds()
            const configuration = await this.createPortalConfiguration(prodPriceIds)

            const portalSession = await this.stripe.billingPortal.sessions.create({
                customer: customerId,
                configuration: configuration.id,
                return_url: `${process.env.APP_URL}/account`
                /* We can't have flow_data because it does not support multiple subscription items
                flow_data: {
                    type: 'subscription_update',

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Ensure the user's active organization has a Stripe customer created (run signup/checkout first) so activeOrganizationCustomerId is populated.
  2. Verify the auth middleware populates req.user.activeOrganizationCustomerId from the org record on each request.
  3. On the client, only show the billing-portal action when the org has billing set up; otherwise prompt the user to subscribe.
  4. If the user switched organizations, reload their session/profile so the active org's customer ID is current.

Example fix

// before
const customerId = req.user?.activeOrganizationCustomerId
if (!customerId) {
    throw new Error('Customer ID is required')
}

// after: structured error with a hint to the caller
if (!customerId) {
    throw new InternalFlowiseError(StatusCodes.BAD_REQUEST, 'Active organization has no Stripe customer. Complete checkout first.')
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate auth state before calling the portal endpoint
function requireOrgCustomer(user: unknown): asserts user is { activeOrganizationCustomerId: string } {
    const u = user as any
    if (!u?.activeOrganizationCustomerId) {
        throw new Error('Active organization has no Stripe customer. Complete checkout first.')
    }
}
requireOrgCustomer(req.user)

Type guard

function hasOrgCustomerId(user: unknown): user is { activeOrganizationCustomerId: string } {
    return typeof (user as any)?.activeOrganizationCustomerId === 'string' && (user as any).activeOrganizationCustomerId.length > 0
}

Try / catch

try {
    const session = await stripeManager.createStripeCustomerPortalSession(req)
} catch (err) {
    if (err instanceof Error && err.message === 'Customer ID is required') {
        return res.status(StatusCodes.BAD_REQUEST).json({ error: 'No billing account for this organization' })
    }
    throw err
}

Prevention

When it happens

Trigger: An authenticated request to the portal-session endpoint by a user whose active organization has no linked Stripe customer ID. Typical for newly created organizations, personal-workspace-only users, or users who switched active org to one without billing setup.

Common situations: User invited to an org that never completed checkout. activeOrganizationCustomerId not populated by the auth/middleware layer. Session stale after org switch. Self-hosted deployment without org billing wired up.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/c8ef63a3d7ceca07. Report an issue: GitHub.