Registry / auth-security / better-auth-affiliates

better-auth-affiliates

JSON →
library0.1.0jsnpmunverified

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.

npm install better-auth-affiliates
INSTALL
IMPORT
SIG · BETTER-AUTH-AFFILI
B
better-auth-affiliates
auth-securityjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

affiliatePlugin
import { affiliatePlugin } from 'better-auth-affiliates'
import affiliatePlugin from 'better-auth-affiliates'
Named export, not default. Only works with Better Auth >=1.4.0.
affiliateClientPlugin
import { affiliateClientPlugin } from 'better-auth-affiliates/client'
import { affiliateClientPlugin } from 'better-auth-affiliates'
Client plugin is in a subpath export '/client' – importing from main path will give undefined.
stripeIntegration
import { stripeIntegration } from 'better-auth-affiliates'
import stripeIntegration from 'better-auth-affiliates'
Named export containing helper functions for Stripe integration.

Sets up affiliate plugin with Better Auth, client plugin, and click tracking with URL ref parameter.

// 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 }) }
Debug
Known issues
gotchaClient plugin must be imported from 'better-auth-affiliates/client', not the main package
fix
Use import { affiliateClientPlugin } from 'better-auth-affiliates/client'
affects: >=0.1.0
breakingRequires better-auth >=1.4.0. Older versions will not work.
fix
Update better-auth to >=1.4.0
affects: >=0.1.0
gotchaCommission 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')
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'better-auth-affiliates/client' or its corresponding type declarations.
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'
affiliateClientPlugin is not a function
Client plugin imported from main package instead of '/client'.
fix
Change import to: import { affiliateClientPlugin } from 'better-auth-affiliates/client'
Type 'number' is not assignable to type 'string'
Providing a number for commissionRate instead of string.
fix
Use a string like '30.00' for commissionRate.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
better-authrequiredPeer dependency required for plugin integration
Agent activity
50 hits · last 30 days
node
40
Perplexity
1
OpenAI (training)
1
Resources
better-auth-affiliates — npm install better-auth-affiliates · libregistry