Repository navigation
fix(billing): block non-admin members from payment/onboarding when subscription lapses - #317
Merged
Merged
Conversation
There was a problem hiding this comment.
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 asok,needs_payment(admin), orblocked(non-admin, optional owner name). - Added a
SubscriptionExpiredNoticeUI 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
force-pushed
the
fix/subscription-expired-non-admin-gate
branch
from
June 29, 2026 12:49
f2233aa to
cfd6143
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.tsxredirected every member to/dashboard/onboardingwhensubscription_statuswasn'tactive/trialing.Fix — gate the inactive-subscription state by role in both server layouts:
Both the dashboard layout (normal navigation) and the onboarding layout (direct
/dashboard/onboardingaccess) 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(...)returnsok/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 fixHow to test
subscription_statusset to an inactive value (e.g.canceled/past_due)./dashboard/onboardingdirectly shows the same notice (no wizard, no brand/competitor re-creation).isCloud()false) → no gating.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)