Basic information
About flowglad-feature-gating
Implement feature access checks using Flowglad to gate premium features, create paywalls, and restrict functionality based on subscription status. Use this skill when adding paid-only features or checking user entitlements.
flowglad-feature-gating is an agent skill listed in the AddMCP.net directory, published by flowglad. Source code is hosted on github.com.
Overview
What is flowglad-feature-gating?
name: flowglad-feature-gating description: Implement feature access checks using Flowglad to gate premium features, create paywalls, and restrict functionality based on subscription status. Use this skill when adding paid-only features or checking user entitlements. license: MIT metadata: author: flowglad version: "1.0.0"
<!-- @flowglad/skill sources_reviewed: 2026-01-21T12:00:00Z source_files:
- platform/docs/sdks/feature-access-usage.mdx
-->
Feature Gating
Abstract
Implement feature access checks using Flowglad's checkFeatureAccess method to gate premium features, create paywalls, and restrict functionality based on subscription status.
Table of Contents
- [Loading State Handling](#1-loading-state-handling) — CRITICAL
- 1.1 [Wait for Billing to Load](#11-wait-for-billing-to-load)
- 1.2 [Skeleton Loading Patterns](#12-skeleton-loading-patterns)
- [Server-Side Gating](#2-server-side-gating) — HIGH
- 2.1 [Verify Access on Server](#21-verify-access-on-server)
- 2.2 [API Route Protection](#22-api-route-protection)
- [Feature Identification](#3-feature-identification) — MEDIUM
- 3.1 [Use Slugs Not IDs](#31-use-slugs-not-ids)
- [Component Wrapper Patterns](#4-component-wrapper-patterns) — MEDIUM
- 4.1 [Feature Gate Component](#41-feature-gate-component)
- 4.2 [Higher-Order Component Pattern](#42-higher-order-component-pattern)
- [Redirect to Upgrade Patterns](#5-redirect-to-upgrade-patterns) — MEDIUM
- 5.1 [Client-Side Redirect](#51-client-side-redirect)
- 5.2 [Server-Side Redirect](#52-server-side-redirect)
1. Loading State Handling
2. Server-Side Gating
Impact: HIGH
Client-side feature checks are for UI purposes only. Any sensitive operation or data access must verify subscription status server-side. Users can bypass client-side checks by modifying frontend code or using browser developer tools.
2.1 Verify Access on Server
Impact: HIGH (security requirement)
Never trust client-side access checks for operations that cost money, access sensitive data, or perform privileged actions.
Incorrect: trusts client-side check for sensitive operation
// API route
export async function POST(req: Request) {
// Client could bypass this by modifying frontend code
const { hasAccess } = await req.json()
if (!hasAccess) {
return Response.json({ error: 'No access' }, { status: 403 })
}
return performSensitiveOperation()
}
Correct: verify server-side
// API route
import { flowglad } from '@/lib/flowglad'
import { auth } from '@/lib/auth'
export async function POST(req: Request) {
const session = await auth()
if (!session?.user?.id) {
return Response.json({ error: 'Unauthorized' }, { status: 401 })
}
const billing = await flowglad(session.user.id).getBilling()
if (!billing.checkFeatureAccess('api-access')) {
return Response.json({ error: 'Upgrade required' }, { status: 403 })
}
return performSensitiveOperation()
}
2.2 API Route Protection
Impact: HIGH (prevents unauthorized access)
Create a reusable pattern for protecting multiple API routes with feature checks.
Incorrect: duplicates check logic everywhere
// routes/generate.ts
export async function POST(req: Request) {
const session = await auth()
const billing = await flowglad(session.user.id).getBilling()
if (!billing.checkFeatureAccess('ai-generation')) {
return Response.json({ error: 'Upgrade required' }, { status: 403 })
}
// ... generation logic
}
// routes/export.ts
export async function POST(req: Request) {
const session = await auth()
const billing = await flowglad(session.user.id).getBilling()
if (!billing.checkFeatureAccess('export')) {
return Response.json({ error: 'Upgrade required' }, { status: 403 })
}
// ... export logic
}
Correct: create reusable middleware/helper
// lib/requireFeature.ts
import { flowglad } from '@/lib/flowglad'
import { auth } from '@/lib/auth'
export async function requireFeature(featureSlug: string) {
const session = await auth()
if (!session?.user?.id) {
return { error: 'Unauthorized', status: 401 }
}
const billing = await flowglad(session.user.id).getBilling()
if (!billing.checkFeatureAccess(featureSlug)) {
return { error: 'Upgrade required', status: 403 }
}
return { userId: session.user.id, billing }
}
// routes/generate.ts
export async function POST(req: Request) {
const result = await requireFeature('ai-generation')
if ('error' in result) {
return Response.json({ error: result.error }, { status: result.status })
}
const { userId, billing } = result
// ... generation logic
}
3. Feature Identification
Impact: MEDIUM
How you reference features affects code maintainability and environment portability.
3.1 Use Slugs Not IDs
Impact: MEDIUM (environment portability)
Feature IDs are auto-generated and differ between development, staging, and production environments. Slugs are stable identifiers you control.
Incorrect: hardcoding Flowglad IDs
// IDs change between environments!
if (billing.checkFeatureAccess('feat_abc123xyz')) {
// Works in dev, breaks in production
}
Correct: use slugs
// Slugs are stable across environments
if (billing.checkFeatureAccess('advanced-analytics')) {
// Works everywhere
}
Define feature slugs in your Flowglad dashboard and reference them consistently in code.
4. Component Wrapper Patterns
( WrappedComponent: ComponentType
, feature: string, redirectTo = '/pricing' ) { return function WithFeatureAccess(props: P) { const { loaded, checkFeatureAccess } = useBilling() const router = useRouter() useEffect(() => { if (loaded && checkFeatureAccess && !checkFeatureAccess(feature)) { router.push(redirectTo) } }, [loaded, checkFeatureAccess, router]) if (!loaded || !checkFeatureAccess) { return } if (!checkFeatureAccess(feature)) { // Show skeleton while redirecting return } return } } // Usage function AnalyticsDashboard() { return
Comments
No comments yet
Be the first to share feedback about this listing. Sign in to leave a comment.
Sign In