@moneydevkit/better-auth
v0.13.0
Published
Better Auth plugin for MoneyDevKit checkout integration
Downloads
1,537
Keywords
Readme
@moneydevkit/better-auth
Better Auth plugin for MoneyDevKit. Automatically links authenticated users to MDK customers.
Installation
npm install @moneydevkit/better-auth better-authYou'll also need a MoneyDevKit UI package for your framework:
Setup
1. Environment variables
MDK_ACCESS_TOKEN=your_api_key
MDK_MNEMONIC=your_wallet_mnemonic2. Server plugin
// lib/auth.ts
import { betterAuth } from "better-auth"
import { moneydevkit } from "@moneydevkit/better-auth"
export const auth = betterAuth({
// ... your config
plugins: [moneydevkit()]
})3. Client plugin
import { createAuthClient } from "better-auth/react"
import { moneydevkitClient } from "@moneydevkit/better-auth/client"
const authClient = createAuthClient({
plugins: [moneydevkitClient()]
})
// Same API as useCheckout().createCheckout from @moneydevkit/nextjs
const result = await authClient.createCheckout({
type: 'AMOUNT',
amount: 500,
currency: 'USD',
successUrl: '/checkout/success',
})
if (result.data) {
window.location.href = result.data.checkoutUrl
}4. Framework setup
Follow the setup guide for your framework's MoneyDevKit package (route handler, checkout page, config):
How it works
The plugin adds a /moneydevkit/checkout endpoint that:
- If user is authenticated: maps
user.id→customer.externalId, auto-fills email/name - If no session: creates checkout without customer info (guest checkout)
This links all checkouts to the same MDK customer record for returning users.
