Skip to content

fix(billing): block non-admin members from payment/onboarding when subscription lapses - #317

Merged
gkhngyk merged 1 commit into
mainfrom
fix/subscription-expired-non-admin-gate
Jun 29, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/subscription-expired-non-admin-gate

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a real bug a customer hit: when an org's trial/subscription ended, a non-owner member who joined via an invite link was shown the payment screen and could walk back to onboarding step 1 and re-create the brand / competitors on the org's already-set-up account.

Root cause — the inactive-subscription state had no role awareness:

  • web/src/app/[locale]/(dashboard)/layout.tsx redirected every member to /dashboard/onboarding when subscription_status wasn't active/trialing.
  • The onboarding page then placed any onboarded user on the plan/payment step regardless of role, and the wizard's "already created" guard is React state (not a DB check), so a member walking back to step 1 could create a duplicate brand + re-add competitors.

Fix — gate the inactive-subscription state by role in both server layouts:

  • admin (incl. the org owner) → renew/payment flow (unchanged).
  • non-admin (manager / analyst / agency_partner) → a blocking "Subscription required — contact your account owner" notice. No payment, no re-onboarding, no access to the wizard.

Both the dashboard layout (normal navigation) and the onboarding layout (direct /dashboard/onboarding access) enforce it, so a non-admin can't reach the payment screen or the wizard by any path.

"Owner" = the org's first admin, surfaced in the message so the member knows who to contact. The lookup uses the caller's RLS client and falls back to a generic wording if it can't read the owner's row (never throws).

New files

  • web/src/lib/billing/subscription-access.ts — evaluateSubscriptionAccess(...) returns ok / needs_payment (admin) / blocked (non-admin, with owner name).
  • web/src/components/billing/subscription-expired-notice.tsx — the contact-your-owner screen (with sign-out).

Type of change

  • fix — Bug fix

How to test

  1. Cloud mode, org with subscription_status set to an inactive value (e.g. canceled/past_due).
  2. As an admin of that org → land on the renew/payment flow (unchanged).
  3. As a non-admin member (manager/analyst) of that org → see the "Subscription required — contact your account owner ()" notice; cannot reach the payment screen, and visiting /dashboard/onboarding directly shows the same notice (no wizard, no brand/competitor re-creation).
  4. Active/trialing org → all members get normal access. Self-hosted (isCloud() false) → no gating.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a billing/onboarding access-control bug in cloud mode where an org with an inactive subscription could funnel non-admin invited members into the payment/onboarding flow, allowing them to navigate back and recreate onboarding resources (e.g., duplicate brand/competitors). The fix introduces a centralized server-side subscription access evaluation and enforces role-aware gating in both the dashboard and onboarding layouts.

Changes:

  • Added evaluateSubscriptionAccess(...) to classify access as ok, needs_payment (admin), or blocked (non-admin, optional owner name).
  • Added a SubscriptionExpiredNotice UI to block non-admins and instruct them to contact the account owner/admin.
  • Updated both dashboard and onboarding server layouts to enforce the role-aware gating in cloud mode.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
web/src/lib/billing/subscription-access.ts Adds centralized subscription access evaluation (role-aware, optional owner lookup).
web/src/components/billing/subscription-expired-notice.tsx Adds the blocking “subscription required” notice UI for non-admins.
web/src/app/[locale]/(onboarding)/layout.tsx Prevents already-onboarded non-admins from re-entering onboarding when subscription is inactive (cloud).
web/src/app/[locale]/(dashboard)/layout.tsx Routes admins to renew flow and blocks non-admins from dashboard access when subscription is inactive (cloud).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,55 @@
import { createClient } from '@/lib/supabase/server';
Comment on lines +32 to +36
export async function evaluateSubscriptionAccess(
supabase: ServerSupabase,
organizationId: string,
role: string,
subscriptionStatus: string | null,
Comment on lines +32 to +43
export async function evaluateSubscriptionAccess(
supabase: ServerSupabase,
organizationId: string,
role: string,
subscriptionStatus: string | null,
): Promise<SubscriptionAccess> {
if (subscriptionStatus && ACTIVE_STATUSES.has(subscriptionStatus)) {
return { state: 'ok' };
}
if (role === 'admin') {
return { state: 'needs_payment' };
}
…bscription lapses

When an org's trial/subscription ended, the dashboard layout redirected
EVERY member to the onboarding wizard, with no role check. An invited
non-owner then saw the payment screen and could walk back to step 1 and
re-create the brand / competitors on the org's existing setup.

Gate the inactive-subscription state by role in both the dashboard and
onboarding server layouts:
- admin (incl. the org owner) -> renew/payment flow (unchanged)
- non-admin (manager/analyst/agency_partner) -> a 'subscription ended,
  contact your account owner' notice; no payment, no re-onboarding

Owner = the org's first admin, surfaced in the message so members know
who to contact (RLS-safe lookup, falls back to a generic wording).
@gkhngyk
gkhngyk force-pushed the fix/subscription-expired-non-admin-gate branch from f2233aa to cfd6143 Compare June 29, 2026 12:49
@gkhngyk
gkhngyk merged commit a626c9f into main Jun 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants