Tutorial

Quickstart

A signed-in app in about three minutes with no account anywhere, then credits bought on Polar's sandbox and spent by a metered action in about five more.

Two checkpoints take you from an empty folder to a signed-in app that sells and spends credits. The first needs no account: the app runs on a local deployment, and sign-in codes print in your terminal. The second adds a Polar sandbox account, so checkout runs on Polar's own test server.

CheckpointAccountsTime
1. A signed-in appNoneAbout 3 minutes
2. Credits bought and spentA Polar sandbox accountAbout 5 minutes
Next: email and webhooksA Resend account, and a Convex account for a cloud deploymentAbout 10 minutes

You need Node 24.11 or later. Deploying is not part of the Quickstart: Deploy takes it from here.

Checkpoint 1: a signed-in app

Create the app

npm create nuxt@latest my-app -- -t gh:qruto/nuxt-backend/templates/starter
cd my-app

The starter is a Nuxt app with the module installed and its backend files written. In an app you already have, nuxt module add is the whole install: the module's install step adds convex, writes the same files into backend/, points the dev script at nuxt-backend dev, swaps <NuxtWelcome /> for <NuxtPage /> and adds a home page when the app has none. It asks a few questions in the terminal, and the defaults are fine for this page. Installation covers strict pnpm, the install through a coding agent and the install by hand.

Start it

npx nuxt-backend dev --anonymous
pnpm nuxt-backend dev --anonymous
yarn nuxt-backend dev --anonymous
bunx nuxt-backend dev --anonymous

npx nuxt-backend dev runs Convex and Nuxt together, and the dev script runs the same command. --anonymous creates a local deployment that needs no account, on macOS, Linux and Windows alike. A plain npm run dev asks instead, and Start without an account is the same answer. The first run writes CONVEX_DEPLOYMENT to .env.local, then gives the deployment its AUTH_SECRET, a SITE_URL of http://localhost:3000 and a BACKEND_ENVIRONMENT of development. Its last check reads backend preflight: …, and the email and billing findings in it are expected until you connect those services.

Sign in with the code in the terminal

Open localhost:3000/login, type your email and ask for a code. No email provider is connected, and a development deployment logs every code, so it prints in the terminal running dev. Paste it, and you are signed in, with a personal workspace of your own.

You should now see your email and your workspace on /app, which the starter's home page opens. In an app you already have, open /settings, which the module mounts.

Checkpoint 2: credits bought and spent

The starter's catalog, backend/billing.catalog.ts, declares two plans and two credit packs. This checkpoint creates them in Polar's sandbox, buys a pack with a test card and spends one credit.

Connect Polar's sandbox

Sign up at sandbox.polar.sh, create an organization and an organization access token, and put the token in .env.local:

.env.local
BILLING_ACCESS_TOKEN=your_sandbox_access_token

Then push it to the deployment and create the catalog in the sandbox:

npx nuxt-backend env push
npx nuxt-backend billing sync
pnpm nuxt-backend env push
pnpm nuxt-backend billing sync
yarn nuxt-backend env push
yarn nuxt-backend billing sync
bunx nuxt-backend env push
bunx nuxt-backend billing sync

billing sync creates the meter, the plans and the packs, and writes their ids to backend/billing.generated.ts. /pricing lists them now.

Buy a credit pack

On /app, press Buy 500 credits. Polar's sandbox checkout opens: pay with the card 4242 4242 4242 4242, any future expiry and any CVC, then press Pay. Back on /app, the balance reads 500. The return from checkout refreshes it, since Polar's webhooks cannot reach a deployment on your machine.

Spend a credit

Press Spend 1 credit. It calls transform from backend/ai.ts, a metered action: it reserves a credit, runs, then settles the spend with Polar, and the balance drops to 499. A run that fails releases its reservation and charges nothing.

You should now see 499 credits on /app and in the credits section of /settings.

In an app you already have, these two buttons are one page:

app/pages/credits.vue
<script setup lang="ts">
import { api } from '#backend/api'

definePageMeta({ auth: true })

const { products } = useBilling()
const { balance, topUp } = useCredits({ meter: 'credits' })
const spend = useAction(api.ai.transform)
</script>

<template>
  <p>{{ balance ?? '…' }} credits</p>
  <button v-if="products?.credits500" @click="topUp(products.credits500.id)">
    Buy 500 credits
  </button>
  <button @click="spend({ prompt: 'hello' })">Spend 1 credit</button>
</template>

definePageMeta({ auth: true }) sends a visitor who is not signed in to /login and back. useCredits reads the balance live, so the page updates the moment a purchase or a spend settles.

Next: email and webhooks

Codes in the terminal and a refresh after checkout cover a first run. Two more steps make development behave like production. The Service map gives the order, and each service's page its keys:

  • Email. Put a Resend key in .env.local as EMAIL_API_KEY, with EMAIL_FROM, and run npx nuxt-backend env push (Resend). In development, mail goes only to Resend's test addresses: sign in as [email protected], and read the code with npx nuxt-backend inbox.
  • Webhooks. npx convex login links the deployment to your Convex account, and a cloud dev deployment has the public URL Polar and Resend post to (Convex). Run npx nuxt-backend billing sync and npx nuxt-backend email sync again to register it.

Develop on real sandboxes covers both, and the AI gateway for a real model call.

Where to go next

  • Build a creative app: the tutorial, from this starter to Panels, a comic-strip maker in production.
  • Service map: every provider, what it powers, and the order to connect them in.
  • What you got: every file, page, route and composable the first run gave you.
  • Feature map: everything else the package does, capability by capability.
  • Run the dev loop: the daily loop, and the other kinds of deployment.
  • Try the demo: Panels, the tutorial's app, running live in sandbox mode, before you build anything.

First-run troubleshooting

What you seeWhy, and the fix
The Nuxt welcome page instead of the appapp/app.vue still renders <NuxtWelcome />. Render <NuxtPage /> instead.
convex dev can't resolve @convex-dev/…Strict pnpm hides the components Convex bundles. Hoist them.
"This app is in test mode and only emails test addresses, so this address can't receive mail here."Email is connected and in test mode, which delivers only to Resend's test addresses. Sign in as [email protected], and read the code in the terminal or with npx nuxt-backend inbox.
"This app can't send email yet."The deployment has no email provider, and it is not a development one, so it does not log codes either. Run npx nuxt-backend env push, which sets BACKEND_ENVIRONMENT on a dev deployment.
/pricing is emptyThe catalog never reached the deployment. With dev running, run npx nuxt-backend billing sync, then see Pricing is empty.
billing sync says the token is invalidIt is a production token. Polar's sandbox takes only a token created in the sandbox itself.

Anything else: Troubleshooting lists every message the package prints, and npx nuxt-backend doctor names what is missing (Diagnose your setup).