Skip to main content
This guide uses subscription persistence, the recommended setup for most applications. It stores Creem customer and subscription identifiers in your Better Auth database and keeps them current through webhooks.

1. Install the plugin

The Creem TypeScript SDK is included as a dependency of the plugin.

2. Configure the server plugin

Add your test API key and a webhook signing secret to the server environment:
.env
Register the plugin in your Better Auth configuration:
lib/auth.ts
The webhook endpoint is registered only when webhookSecret is present.

3. Generate the database schema

The plugin adds creemCustomerId and hadTrial to the Better Auth user model and creates a creem_subscription model. With Better Auth’s built-in Kysely adapter, apply the schema directly:
When Prisma, Drizzle, or another ORM owns your schema, generate the schema instead and apply it with that ORM’s migration tooling:
See the Better Auth database documentation when your adapter requires manual migration steps.

4. Configure the client plugin

lib/auth-client.ts
If client and server are separate applications, install @creem_io/better-auth in both.

5. Create a checkout

The signed-in user’s email is used when no customer is supplied. Their Better Auth user ID is added to checkout metadata as referenceId.
app/pricing/subscribe-button.tsx

6. Register the webhook

In the Creem dashboard, point a test-mode webhook at:
/api/auth is Better Auth’s default base path. Use your configured base path if you changed it. For local development, expose the application over HTTPS with a tunnel and register that URL. Once Creem delivers subscription events, the plugin updates the local subscription record. You can also add access callbacks for application-specific provisioning.

Continue

Configuration

Review every plugin option and persistence behavior.

Client API

Add the portal, cancellation, access checks, and transaction history.