Skip to content

Payments in Nuxt with Polar and better-auth

Accept payments with Polar through the better-auth plugin: a Polar customer on sign-up, checkout for signed-in users and the customer portal.

Nuxt Starter Kit uses Polar to accept payments. Polar is a Merchant of Record: it is the legal seller and handles taxes for you. It provides an API for creating and managing subscriptions, invoices and payments.

Getting Started

To get started with Polar, you need to create an account and an access token. You can do this by following the instructions in the Polar documentation.

Set the following environment variables in apps/web/.env:

NUXT_PRIVATE_POLAR_ACCESS_TOKEN=
NUXT_PRIVATE_POLAR_ORGANIZATION_ID=
NUXT_PRIVATE_POLAR_SERVER=sandbox

NUXT_PRIVATE_POLAR_ACCESS_TOKEN

Required. This is your Polar access token. You can generate one in your Polar account settings. This token is used to authenticate your requests to the Polar API.

NUXT_PRIVATE_POLAR_ORGANIZATION_ID

This is the ID of your Polar organization. You can find this in your Polar account settings. This ID is used to identify your organization when making requests to the Polar API.

NUXT_PRIVATE_POLAR_SERVER

The Polar server you want to use: sandbox (default) for testing with your Sandbox, or production for production.

The /pricing page loads the Polar products at build time. Production builds need the Polar values, otherwise the page prerenders without products.

How It Works

The kit uses the Polar plugin for better-auth, configured in apps/web/layers/auth/server/utils/polar.ts:

  • Customer on sign-up: every new user gets a Polar customer with the user ID as external ID.
  • Checkout: signed-in users start a Polar checkout and return to /dashboard afterwards.
  • Customer portal: users manage their subscription, payment method and invoices in Polar's customer portal.

On the client, useAuth() exposes the Polar customer state (polarState) and the user's activeSubscription. The billing page in the dashboard uses them.

Subscriptions & Lifetime Deals

The starter kit is designed to support subscriptions (free & Pro) and a lifetime deal.

Products and pricing live in the apps/web/layers/payment layer. The billing pages are in the dashboard layer.