Better Auth Affiliates
raw JSON → 0.1.0 verified Sat May 09 auth: no javascript
A complete affiliate and referral system plugin for Better Auth v0.1.0, enabling affiliate links, click tracking, commission management, and Stripe integration with recurring commissions. Ships TypeScript types, Zod validation, and pre-built React dashboard components. Works with any Better Auth database adapter and requires better-auth >= 1.4.0.
Common errors
error Cannot find module 'better-auth-affiliates/client' or its corresponding type declarations. ↓
cause Client plugin imported from wrong path or package not installed.
fix
Install the package: npm install better-auth-affiliates, and import from 'better-auth-affiliates/client'
error affiliateClientPlugin is not a function ↓
cause Client plugin imported from main package instead of '/client'.
fix
Change import to: import { affiliateClientPlugin } from 'better-auth-affiliates/client'
error Type 'number' is not assignable to type 'string' ↓
cause Providing a number for commissionRate instead of string.
fix
Use a string like '30.00' for commissionRate.
Warnings
gotcha Client plugin must be imported from 'better-auth-affiliates/client', not the main package ↓
fix Use import { affiliateClientPlugin } from 'better-auth-affiliates/client'
breaking Requires better-auth >=1.4.0. Older versions will not work. ↓
fix Update better-auth to >=1.4.0
gotcha Commission rate is a string like '30.00', not a number. Passing a number will cause runtime errors. ↓
fix Use string format for commissionRate (e.g., '30.00')
Install
npm install better-auth-affiliates yarn add better-auth-affiliates pnpm add better-auth-affiliates Imports
- affiliatePlugin wrong
import affiliatePlugin from 'better-auth-affiliates'correctimport { affiliatePlugin } from 'better-auth-affiliates' - affiliateClientPlugin wrong
import { affiliateClientPlugin } from 'better-auth-affiliates'correctimport { affiliateClientPlugin } from 'better-auth-affiliates/client' - stripeIntegration wrong
import stripeIntegration from 'better-auth-affiliates'correctimport { stripeIntegration } from 'better-auth-affiliates'
Quickstart
// auth.ts
import { betterAuth } from 'better-auth'
import { affiliatePlugin } from 'better-auth-affiliates'
export const auth = betterAuth({
plugins: [
affiliatePlugin({
commissionRate: '30.00',
commissionType: 'percentage',
commissionDurationMonths: 12,
cookieDurationDays: 30,
}),
],
})
// auth-client.ts
import { createAuthClient } from 'better-auth/client'
import { affiliateClientPlugin } from 'better-auth-affiliates/client'
export const authClient = createAuthClient({
plugins: [affiliateClientPlugin()],
})
// Track click on landing page
const code = new URLSearchParams(window.location.search).get('ref')
if (code) {
await authClient.affiliate.trackClick({ code })
}