Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(billing): block tracking + features for orgs without active subscription (#56)
Gökhan Geyikcb8056d153d9
diff --git a/server/src/config/plans.js b/server/src/config/plans.jsindex fe8896f3c..8c4bfd708 100644--- a/server/src/config/plans.js+++ b/server/src/config/plans.js@@ -112,6 +112,19 @@ export function isCloud() {return process.env.IS_CLOUD === 'true';}+/**+ * Whether an organization's Stripe subscription is in a state that grants+ * access to billed features. `trialing` counts — it's a paid plan in its+ * free-trial period. Everything else (incomplete, canceled, past_due,+ * unpaid) does NOT grant access.+ *+ * Self-hosted instances always return true since billing doesn't apply.+ */+export function isSubscriptionActive(status) {+ if (!isCloud()) return true;+ return status === 'active' || status === 'trialing';+}+export function getPlan(planId) {if (!isCloud()) return PLANS.self_hosted;return PLANS[planId] || PLANS.starter;diff --git a/server/src/lib/plan-guard.js b/server/src/lib/plan-guard.jsindex 8d04d4fe2..19685f928 100644--- a/server/src/lib/plan-guard.js+++ b/server/src/lib/plan-guard.js@@ -4,6 +4,7 @@ import {hasFeature,isWithinLimit,isCloud,+ isSubscriptionActive,} from '../config/plans.js';export class PlanLimitError extends Error {@@ -37,8 +38,15 @@ async function resolveOrgPlan(userId) {.eq('id', profile.organization_id).single();- if (!org || org.subscription_status !== 'active') {- return getPlan('starter');+ // Block feature access for orgs without an active or trialing Stripe+ // subscription. Previously this fell back to starter, which silently+ // granted billed features (volume fetch, content generation, etc.) to+ // unsubscribed signups.+ if (!isSubscriptionActive(org?.subscription_status)) {+ throw new PlanLimitError(+ 'An active subscription or free trial is required. Please choose a plan to continue.',+ 402,+ );}return getPlan(org.plan);diff --git a/server/src/routes/tracking.js b/server/src/routes/tracking.jsindex cb6ff43a9..ad805ed94 100644--- a/server/src/routes/tracking.js+++ b/server/src/routes/tracking.js@@ -2,7 +2,7 @@ import { Router } from 'express';import { createJob, getJob, cancelJob } from '../lib/job-manager.js';import { runTrackingJob } from '../lib/job-runner.js';import supabaseAdmin from '../config/supabase.js';-import { isCloud, getPlan } from '../config/plans.js';+import { isCloud, getPlan, isSubscriptionActive } from '../config/plans.js';const router = Router();@@ -154,7 +154,7 @@ router.post('/analyze-new', async (req, res) => {return res.json({ success: true, newCount: 0, message: 'All prompts already analyzed' });}- // --- Cloud-mode rate limiting ---+ // --- Cloud-mode subscription gate + rate limiting ---if (isCloud()) {const { data: org } = await supabaseAdmin.from('organizations')@@ -162,9 +162,17 @@ router.post('/analyze-new', async (req, res) => {.eq('id', brand.organization_id).single();- const plan = !org || org.subscription_status !== 'active'- ? getPlan('starter')- : getPlan(org.plan);+ // Block tracking outright when the org's Stripe subscription isn't+ // active or trialing. Previously this fell back to starter limits,+ // which let unsubscribed signups run jobs silently.+ if (!isSubscriptionActive(org?.subscription_status)) {+ return res.status(402).json({+ message:+ 'An active subscription or free trial is required to run tracking. Please choose a plan to continue.',+ });+ }++ const plan = getPlan(org.plan);const { maxDailyOnDemand, onDemandCooldownMinutes } = plan.limits;diff --git a/server/src/server.js b/server/src/server.jsindex a9abedb38..2e63922a1 100644--- a/server/src/server.js+++ b/server/src/server.js@@ -16,7 +16,12 @@ import { runTrackingJob } from './lib/job-runner.js';import { parseScraperResponse } from './lib/cloro-scraper.js';import { handleScraperResult } from './lib/cloro-result-handler.js';import supabaseAdmin from './config/supabase.js';-import { getPlan, hasFeature, isCloud } from './config/plans.js';+import {+ getPlan,+ hasFeature,+ isCloud,+ isSubscriptionActive,+} from './config/plans.js';const app = express();app.set('trust proxy', 1);@@ -107,14 +112,20 @@ async function runDailyTracking() {.select('plan, subscription_status').eq('id', brand.organization_id).single();- orgPlanCache[brand.organization_id] =- !org || org.subscription_status !== 'active'- ? getPlan('starter')- : getPlan(org.plan);+ // Skip orgs without an active or trialing Stripe subscription.+ // Previously this fell back to starter limits, which silently kept+ // running daily monitoring (and Cloro / AI provider spend) for+ // unsubscribed signups.+ if (!isSubscriptionActive(org?.subscription_status)) {+ orgPlanCache[brand.organization_id] = null;+ } else {+ orgPlanCache[brand.organization_id] = getPlan(org.plan);+ }}}const plan = orgPlanCache[brand.organization_id];+ if (!plan) continue; // unsubscribed → skip silentlyif (!hasFeature(plan, 'daily_monitoring')) continue;const { count } = await supabaseAdmin