Complete guide to implementing license-based paywalls in your SaaS application using Chariow API with AI coding tools
This guide shows you how to use Chariow’s License API to implement a paywall in your SaaS application. Whether you’re building with Lovable, Cursor, Bolt, or any AI coding assistant, this guide provides everything you need including ready-to-use AI prompts.
This guide assumes you have a Chariow store with a License type product created. If you haven’t set one up yet, create your license product first.
Create a license paywall system for my Next.js application with these requirements:1. Create an API route at /api/validate-license that: - Accepts POST requests with { licenseKey: string } - Calls Chariow API: GET https://api.chariow.com/v1/licenses/{licenseKey} - Uses Bearer token authentication with CHARIOW_API_KEY environment variable - Returns { valid: true/false, error?: string, license?: object } - Check is_active and is_expired fields from the response2. Create a LicenseGate component that: - Shows a license key input form when not validated - Stores valid license key in localStorage - Checks localStorage on mount to auto-validate returning users - Renders children only when license is valid - Shows loading state during validation - Displays error messages for invalid licenses3. Style the license form with Tailwind CSS: - Centre the form on the page - Use clean, professional styling - Include a link to purchase a licenseEnvironment variable needed: CHARIOW_API_KEY (store API key)
Extend the license paywall system with device activation:1. Generate a unique device identifier: - For web apps: combine user agent + screen resolution + timezone - Hash the result to create a consistent device ID - Store the device ID in localStorage2. Create /api/activate-license endpoint: - Accepts POST with { licenseKey, deviceId } - Calls Chariow API: POST https://api.chariow.com/v1/licenses/{key}/activate - Body: { device_identifier: deviceId } - Handle "Activation limit reached" error gracefully3. Update LicenseGate component: - After validating license, call activate endpoint - Show remaining activations count to user - Handle activation errors with user-friendly messages4. Add a "Manage Devices" section showing: - Current activation count - Maximum activations allowed - Option to deactivate current device
Implement feature-gated licensing where different license tiers unlock different features:1. Create a useLicense hook that: - Validates license on app load - Returns { isValid, tier, features, expiresAt } - Tier is determined by the product name or metadata from Chariow2. Create a FeatureGate component: - Accepts requiredTier prop (e.g., "pro", "enterprise") - Shows upgrade prompt if user's tier is insufficient - Renders children if tier requirement is met3. Example usage: <FeatureGate requiredTier="pro"> <AdvancedAnalytics /> </FeatureGate>4. Create an upgrade modal that: - Shows current vs required tier - Links to Chariow checkout for the upgrade product - Includes feature comparison
Add offline support to the license system:1. Cache license validation result locally: - Store validation timestamp - Store license expiry date - Store full license object2. Implement validation logic: - If online: validate with Chariow API - If offline: check cached validation (valid for 7 days) - If cache expired: show offline warning but allow limited access3. Add periodic re-validation: - Re-validate every 24 hours when online - Update cache on successful validation - Handle network errors gracefully4. Show license status indicator: - Green: validated online today - Yellow: using cached validation - Red: cache expired, needs connection
Create a license system for an Electron desktop app:1. Main process license manager: - Store license in electron-store (encrypted) - Validate on app launch - Re-validate every 24 hours - Send validation status to renderer via IPC2. Preload script: - Expose safe license APIs to renderer - licenseAPI.validate(key) - licenseAPI.getStatus() - licenseAPI.activate()3. Renderer license UI: - License entry screen on first launch - License status in settings - "Manage Activations" option4. Device identifier: - Use machine-id package for consistent device ID - Pass to Chariow activation endpoint5. Offline handling: - Cache validation for 7 days - Show "Offline Mode" indicator - Block app after cache expires
Integrate license validation with Supabase authentication:1. Create a Supabase edge function at /validate-license: - Verify user is authenticated - Store validated licenses in a 'user_licenses' table - Link license to user ID2. Database schema: CREATE TABLE user_licenses ( id UUID PRIMARY KEY, user_id UUID REFERENCES auth.users, license_key TEXT NOT NULL, validated_at TIMESTAMP, expires_at TIMESTAMP, status TEXT );3. React hook useUserLicense: - Check if current user has valid license - Sync license status on login - Handle multi-device scenarios4. Row Level Security: - Users can only see their own licenses - Enable realtime subscriptions for status updates