Frameworks Solid

Solid

Gate features in a SolidJS extension popup with createUser from @extensionbill/sdk/solid.

createUser(bill) from @extensionbill/sdk/solid gives your component accessors for the current user, so <Show> blocks update by themselves after a purchase. Shared setup: Pick your stack.

Quick start

  1. Create the project.

    npm create vite@latest my-extension -- --template solid-ts
    cd my-extension
    npm install @extensionbill/sdk
    npm install -D @crxjs/vite-plugin
    
  2. Add the manifest. Replace vite.config.ts; CRXJS builds every file the manifest references:

    // vite.config.ts
    import { defineConfig } from 'vite'
    import solid from 'vite-plugin-solid'
    import { crx } from '@crxjs/vite-plugin'
    
    export default defineConfig({
      plugins: [
        solid(),
        crx({
          manifest: {
            manifest_version: 3,
            name: 'My Extension',
            version: '1.0.0',
            permissions: ['storage', 'alarms'],
            background: { service_worker: 'src/background.ts', type: 'module' },
            action: { default_popup: 'index.html' },
          },
        }),
      ],
    })
    
  3. Create the client and the background.

    # .env.development
    VITE_EXTENSIONBILL_PUBLISHABLE_KEY=pk_test_…
    
    // src/bill.ts
    import { ExtensionBill } from '@extensionbill/sdk'
    
    export const bill = ExtensionBill({
      publishableKey: import.meta.env.VITE_EXTENSIONBILL_PUBLISHABLE_KEY,
    })
    
    // src/background.ts
    import { bill } from './bill'
    
    bill.startBackground()
    

    Keep startBackground() at the top level (why).

  4. Gate your popup. Replace src/App.tsx (the template’s src/index.tsx already renders it):

    // src/App.tsx
    import { Show } from 'solid-js'
    import { createUser } from '@extensionbill/sdk/solid'
    import { bill } from './bill'
    
    export default function App() {
      const account = createUser(bill)
    
      return (
        <Show when={!account.loading()} fallback={<p>Loading…</p>}>
          <Show
            when={account.hasAccess('pro')}
            fallback={
              <main>
                <button onClick={() => bill.openCheckout()}>Upgrade to Pro</button>
                <button onClick={() => bill.openRestore()}>Already paid? Restore</button>
              </main>
            }
          >
            <main>
              <p>Pro feature unlocked.</p>
              <button onClick={() => bill.openPortal()}>Manage subscription</button>
            </main>
          </Show>
        </Show>
      )
    }
    
  5. Test a purchase. Run npm run dev, load the dist folder unpacked and buy Pro with a sandbox buyer (steps).

Advanced

Drop-in paywall

Swap your upgrade buttons for the ready-made Paywall UI. Mount it in onMount and pass the returned cleanup function to onCleanup:

// src/Paywall.tsx
import { onCleanup, onMount } from 'solid-js'
import { mountPaywall } from '@extensionbill/sdk/paywall'
import { bill } from './bill'

export function Paywall() {
  let host!: HTMLDivElement
  onMount(() => onCleanup(mountPaywall(host, bill, { title: 'Upgrade to Pro', theme: 'auto' })))
  return <div ref={host} />
}

Use fallback={<Paywall />} on the hasAccess <Show>. Every option: Paywall UI.

What createUser returns

const { user, loading, error, hasAccess, refresh } = createUser(bill)

user(), loading() and error() are accessors (meaning of each field). hasAccess() reads user(), so it is reactive in JSX and createMemo().

Call createUser(bill) inside a component or root: it unsubscribes with onCleanup when its owner is disposed. Every component that calls it shares one load.

Keys per build

npm run build reads .env.production: put VITE_EXTENSIONBILL_PUBLISHABLE_KEY=pk_live_… there. Live keys work after going live.

Other build tools

  • WXT: npx wxt@latest init my-extension with the Solid template, then the WXT setup with modules: ['@wxt-dev/module-solid']. App.tsx goes in entrypoints/popup/.

Troubleshooting

Background, key and extension ID problems are covered in the shared troubleshooting.

Next steps