Skip to main content
If your app signs users in with Better Auth, the @agentaos/better-auth plugin connects AgentaOS to those users. It adds three endpoints to your auth server:

Before you start

  1. In the dashboard, create the products your users can buy. Copy each product’s link ID from the product page.
  2. Open Developers → API keys and create a key. A key that starts with sk_test_ works in test mode.
  3. Open Settings → Developers → Webhooks and set the URL to https://your-domain.com/api/auth/agentaos/webhook. Click Reveal signing secret and copy the secret.

Install

Add the plugin to your auth server

auth.ts
A user can only buy a product that is in products, by its slug. The product, the price and the return URLs come from your server, not from the browser.

Start a checkout from the browser

auth-client.ts
In test mode, pay with the card 4242 4242 4242 4242, any future date and any CVC.

Handle events

onEvent receives every event after its signature is checked. For checkout.session.completed, userId is the user who started the checkout. In your handler:
  • Give the user the product in event.data.linkId.
  • Ignore test events in live mode: check event.data.livemode.
  • Give access only once per checkout, for example by saving event.data.sessionId. An event can arrive more than once.
The full list of events is in Webhook events.