affiliate-better-auth is a specialized plugin designed to integrate referral and affiliate tracking capabilities into applications built with the Better Auth authentication system. It currently stands at version 0.6.6, with recent releases indicating an active development cadence, though the changelog mentions `0.1.0` for multiple versions. The library simplifies the process of adding referral links and tracking by automatically creating necessary database schemas via the Better Auth adapter. It provides both server-side and client-side plugins to manage referral code generation, cookie issuance for tracking, and recording referrals upon new user creation. Its key differentiators include its tight integration with the Better Auth ecosystem, offering a streamlined solution for applications already using Better Auth for authentication, rather than a standalone, more complex affiliate platform.
npm install affiliate-better-authVerified import paths — ran on the pinned version, not inferred.
Demonstrates server-side initialization of `affiliate-better-auth` by integrating `affiliatePlugin` into the `betterAuth` instance, enabling referral tracking functionalities and automatic schema generation.
Always check the release notes for both `affiliate-better-auth` and `better-auth` when upgrading major versions. Ensure your `better-auth` peer dependency range is compatible.
Communicate cookie usage clearly to users. For critical referral flows, consider fallback mechanisms or alternative tracking methods alongside cookie-based tracking. Ensure your frontend properly calls `POST /affiliate/issue-cookie`.
Review the automatically generated schema. If conflicts arise, you may need to manually adjust your database schema or fork the plugin to customize schema generation if allowed by Better Auth's plugin API.
Rely on the npm package version for compatibility and feature tracking (e.g., `0.6.6`). For detailed change information, consult the GitHub repository directly if the README/changelog is ambiguous.
Run `pnpm add affiliate-better-auth better-auth` (or `npm i` / `yarn add`) in your project root to ensure both the plugin and its peer dependency are correctly installed.
Ensure `affiliatePlugin()` is included in the `plugins` array when configuring `betterAuth` on the server: `betterAuth({ plugins: [affiliatePlugin()] })`.Install a compatible version of `better-auth`. For example, `npm install better-auth@^1.3.0` or update your `package.json` and run `npm install`.