The `better-auth-lead` package is a plugin for the `better-auth` ecosystem, designed to extend its core functionality with lead management capabilities. It facilitates features like newsletter sign-ups, waitlists, and general lead capture by providing a dedicated database table (`leads`) and a robust API. Currently at version 0.4.0, the package is in active development, implying potential API changes in minor versions before reaching a stable 1.0 release. Key differentiators include its seamless integration with `better-auth`'s server and client infrastructure, built-in support for email verification with customizable sending logic, and the ability to define and validate lead metadata using standard schema libraries like Zod or Valibot. This allows developers to quickly add lead generation features with strong type safety and validation.
npm install better-auth-leadVerified import paths — ran on the pinned version, not inferred.
This code snippet demonstrates how to configure the `better-auth-lead` server plugin within `createBetterAuth`, including custom logic for sending verification emails and handling post-verification actions. It includes basic rate-limiting for email sending.
Consult the latest README and changelog for specific updates and migration instructions when upgrading. Pin to exact patch versions if stability is critical.
Ensure you run `npx auth@latest generate` (or `pnpm dlx auth@latest generate`, `yarn dlx auth@latest generate`, `bun x auth@latest generate`) from your project root after plugin installation and configuration.
Enhance your `sendVerificationEmail` function with more comprehensive rate-limiting based on IP, email, or other factors, and consider using dedicated email service providers that offer built-in spam protection.
Change `import { leadClient } from 'better-auth-lead';` to `import { leadClient } from 'better-auth-lead/client';` in your client-side setup file.Run your `better-auth` migration command, typically `npx auth@latest generate`, from your project's root directory.
Verify that `plugins: [leadClient()]` is included in your `createAuthClient` call in your client-side authentication setup file.
Adjust the `metadata` payload on the client to match the expected structure and types defined by the server's validation schema (e.g., Zod schema).