← Back to DocsExamples

Code Examples

Real-world examples to help you integrate PaywallOS faster.

Basic Button Protection

Protect any button by adding the verb= attribute:

export default function ExportButton() {
  const handleExport = () => {
    // This only runs if user has access
    exportToCSV()
  }
  
  return (
    <button 
      verb="export_data"
      onClick={handleExport}
      className="btn-primary"
    >
      Export to CSV
    </button>
  )
}

Protected Section

Protect entire components by wrapping in a div with verb=:

export default function Dashboard() {
  return (
    <div>
      <h1>Dashboard</h1>
      
      {/* Anyone can see this */}
      <BasicStats />
      
      {/* Only Pro+ users can access this */}
      <div verb="advanced_analytics">
        <AdvancedAnalytics />
        <RevenueChart />
        <PredictiveInsights />
      </div>
    </div>
  )
}

Using the Hook

Programmatically check access with the usePaywallOS hook:

import { usePaywallOS } from '@/lib/paywall-sdk'

export default function FeatureCard() {
  const { checkVerb } = usePaywallOS(apiKey, appId, userId, userTier)
  
  const handleClick = async () => {
    const response = await checkVerb('premium_feature')
    
    if (response.ok) {
      activateFeature()
    } else if (response.denied) {
      console.log(response.reason?.message) // "Upgrade to Pro"
    }
  }
  
  return (
    <button onClick={handleClick}>
      Premium Feature
      {userTier === 'free' && <Badge>Pro</Badge>}
    </button>
  )
}

Conditional Rendering

Show different UI based on user tier:

import { usePaywallOS } from '@/lib/paywall-sdk'

export default function FeatureToggle() {
  const { checkVerb } = usePaywallOS(apiKey, appId, userId, userTier)
  const [canExport, setCanExport] = useState(false)
  
  useEffect(() => {
    checkVerb('export_data').then(r => setCanExport(r.ok === true))
  }, [])
  
  return (
    <div>
      {canExport ? (
        <button onClick={handleExport}>
          Export Data
        </button>
      ) : (
        <div>
          <Lock /> Export (Pro feature)
          <Link href="/pricing">Upgrade</Link>
        </div>
      )}
    </div>
  )
}

Multiple Verbs

Check multiple verbs at once:

export default function ActionMenu() {
  return (
    <div className="dropdown-menu">
      <button verb="edit_content">
        Edit
      </button>
      
      <button verb="delete_content">
        Delete
      </button>
      
      <button verb="share_content">
        Share
      </button>
      
      <button verb="export_content">
        Export
      </button>
    </div>
  )
}

// PaywallOS checks each verb independently
// and blocks/allows based on user's tier

Show Usage Limits

Display usage information to users:

import { usePaywallOS } from '@/lib/paywall-sdk'

export default function ExportButton() {
  const { checkVerb } = usePaywallOS(apiKey, appId, userId, userTier)
  const [usage, setUsage] = useState(null)
  
  useEffect(() => {
    checkVerb('export_data').then(response => {
      if (response.ok) setUsage(response.receipt)
    })
  }, [])
  
  return (
    <div>
      <button verb="export_data">
        Export Data
      </button>
      
      {usage && (
        <p className="text-sm text-muted-foreground">
          {usage.remaining} of {usage.limit} exports remaining
        </p>
      )}
    </div>
  )
}
Want More Examples?

Check out the PaywallOS reference app for a complete Next.js example with Stripe, feature gating, and docs.

PaywallOS Sandbox

The OpenVerb JSON library defines what actions exist in the app.

Analytics
dashboard.view
Access to the main analytics dashboard and basic metrics.
data.export
Export reports and raw data to CSV or PDF formats.
data.streaming
Access to real-time websocket data and live feed updates.
AI
ai.insights
Generate automated summaries and trend detection from datasets.
ai.forecast
Access to predictive modeling and future trend forecasting.
Collaborate
team.collaboration
Shared workspaces, comments, and team-based tagging.
Developer
api.custom_keys
Generate and manage programmatic API keys for data integration.
Service
support.priority
Priority ticket handling and 24/7 technical support access.
8 verbs loaded from openverb.core.json

Subscription tiers determine pricing. Each tier unlocks specific verbs.

Free
Free
dashboard.view
1 verb included
Pro
$29/mo
dashboard.view
data.export
ai.insights
3 verbs included
Business
$99/mo
dashboard.view
data.export
data.streaming
ai.insights
ai.forecast
team.collaboration
api.custom_keys
support.priority
8 verbs included

The access control matrix. Which verbs are allowed on which tiers.

VerbFreeProBusiness
dashboard.view
data.export
50/monthly
data.streaming
ai.insights
20/monthly
ai.forecast
team.collaboration
api.custom_keys
support.priority
Active User
Try an Action