Fundamentals

Better Auth Plugin

Add RevKeen billing, checkout, and customer portal to your Better Auth app

Not yet released. @revkeen/better-auth is not published to npm, so it cannot be installed yet. This page describes the planned plugin and will be updated with install instructions when it is released. To integrate RevKeen today, use the TypeScript SDK directly.

@revkeen/better-auth is a Better Auth plugin for your own Better Auth app. It integrates RevKeen billing into the authentication you already run: it creates RevKeen customers on signup, generates checkout sessions, exposes a customer billing portal, and verifies webhook signatures. It is not related to how you sign in to RevKeen itself.

Server setup

import { betterAuth } from "better-auth";
import { revkeen } from "@revkeen/better-auth";
import { RevKeenClient } from "@revkeen/sdk";

const rk = new RevKeenClient({ apiKey: process.env.REVKEEN_API_KEY! });

export const auth = betterAuth({
  // ... your existing config
  plugins: [
    revkeen({
      client: rk,
      createCustomerOnSignUp: true,
      checkout: {
        successUrl: "/thank-you",
        cancelUrl: "/pricing",
      },
      portal: true,
      webhooks: {
        secret: process.env.REVKEEN_WEBHOOK_SECRET!,
        onEvent: {
          "payment.succeeded": async (event) => {
            console.log("Payment succeeded:", event.data.object);
          },
          "subscription.cancelled": async (event) => {
            console.log("Subscription cancelled:", event.data.object);
          },
        },
      },
    }),
  ],
});

Client setup

import { createAuthClient } from "better-auth/client";
import { revkeenClient } from "@revkeen/better-auth/client";

export const authClient = createAuthClient({
  plugins: [revkeenClient()],
});

Usage

Create a checkout session

const { url } = await authClient.revkeen.checkout({
  priceId: "price_xxx",
});

// Redirect to checkout
window.location.href = url;

Get customer billing portal data

const portal = await authClient.revkeen.portal();

console.log(portal.subscriptions); // Active subscriptions
console.log(portal.invoices);      // Recent invoices
console.log(portal.paymentMethods); // Saved payment methods

How it works

  1. On signup — the plugin creates a RevKeen customer via the SDK and stores the customer ID in user metadata
  2. Checkout — POST /api/auth/revkeen/checkout creates a checkout session tied to the RevKeen customer
  3. Portal — GET /api/auth/revkeen/portal returns the customer's subscriptions, invoices, and payment methods
  4. Webhooks — POST /api/auth/revkeen/webhooks verifies the signature and dispatches to your handlers

Configuration reference

OptionTypeDefaultDescription
clientRevKeenClientrequiredPre-configured SDK instance
createCustomerOnSignUpbooleantrueAuto-create RevKeen customer on signup
checkout.successUrlstring—Default redirect after payment
checkout.cancelUrlstring—Default redirect on cancel
portalbooleanfalseEnable customer portal endpoint
webhooks.secretstring—Webhook signing secret
webhooks.onEventRecord<string, handler>—Event handlers by type

Next Steps

Owner: david · Reviewed 30 Sep 2026 · Next review 29 Dec 2026

On this page