Better Auth Waitlist Plugin

3.0.1 · active · verified Wed Apr 22

The `better-auth-waitlist` package, currently at version 3.0.1, is a lightweight and production-ready plugin designed to integrate comprehensive waitlist management into the Better Auth authentication system. It offers features such as administrative approval workflows, restrictions based on email domains, and highly customizable validation for waitlist entries. The package is optimized for minimal bundle size, weighing approximately ~22 kB minified and ~3.5 kB gzipped, and lists `zod` as its only direct runtime dependency. Shipping exclusively as an ES module (ESM), it mandates a Node.js environment of version 18 or higher. Its primary differentiators include deep integration with Better Auth, flexible configuration options for various waitlist use cases (e.g., capacity limits, auto-approval, custom data fields), and client-side utilities for seamless application integration, supporting operations like joining, status checks, and admin-only actions such as listing, finding, approving, and rejecting entries.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure the `better-auth-waitlist` plugin for both server-side Better Auth initialization and client-side application integration. It includes examples of defining custom fields and auto-approval logic for the server plugin, setting up the client with a base URL, and performing common waitlist operations such as joining and checking entry status. It also highlights the crucial step of running database migrations.

import { betterAuth } from "better-auth";
import { waitlist } from "better-auth-waitlist";
import { createAuthClient } from "better-auth/react";
import { waitlistClient } from "better-auth-waitlist/client";

// Server-side: Initialize Better Auth with the waitlist plugin
export const auth = betterAuth({
  plugins: [
    waitlist({
      enabled: true,
      allowedDomains: ["@example.com", "@company.org"],
      maximumWaitlistParticipants: 1000,
      // Example of adding custom fields and auto-approval logic
      additionalFields: {
        department: { type: "string", required: true },
        additionalInfo: { type: "string", required: false }
      },
      autoApprove: (entry) => entry.email.endsWith('@company.org')
    })
  ]
});

// Client-side: Initialize the Better Auth client with the waitlist client plugin
export const authClient = createAuthClient({
  baseURL: process.env.NEXT_PUBLIC_AUTH_URL ?? '', // Ensure this environment variable is set
  plugins: [waitlistClient()]
});

async function demonstrateWaitlist() {
  // Important: Run `npx @better-auth/cli migrate` once to create the necessary database tables.

  // Join the waitlist
  try {
    const joinResult = await authClient.waitlist.join({
      email: "user@example.com",
      department: "Engineering",
      name: "Jane Smith",
      additionalInfo: "Need access to internal tools"
    });
    console.log("Joined waitlist:", joinResult);

    // Check waitlist status
    const status = await authClient.waitlist.checkStatus({
      email: "user@example.com"
    });
    console.log("Waitlist status:", status);

    // Example of admin operations (requires admin role and authenticated client)
    // const allEntries = await authClient.waitlist.list();
    // console.log('All waitlist entries (admin-only):', allEntries);
    // await authClient.waitlist.approve({ id: joinResult.id }); // Assuming joinResult contains an ID
    // console.log('Entry approved by admin.');
  } catch (error) {
    console.error("Waitlist operation failed:", error);
  }
}

demonstrateWaitlist();

view raw JSON →