@agentaos/better-auth plugin connects AgentaOS to those users. It adds three endpoints to your auth server:
Before you start
- In the dashboard, create the products your users can buy. Copy each product’s link ID from the product page.
- Open Developers → API keys and create a key. A key that starts with
sk_test_works in test mode. - 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
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
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.