npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-invite

v0.5.7

Published

A better-auth plugin that allows you to invite users to your app.

Readme

Features

  • 👤 Keep track of who created and who accepted the invite.
  • 🧾 Create and manage invitation codes to control user sign-ups.
  • 📩 Send invitations via email, provide a shareable URL, or generate an invitation code.
  • 🛡️ Automatically assign or upgrade roles when invites are used.
  • 📊 Track each invitation's usage and enforce maximum uses.
  • 🧩 Support multiple token types, including default, code, or custom tokens.
  • 🍪 Store tokens securely in browser cookies for seamless activation.
  • ⚙️ Fully customize behavior for redirects, token expiration, and email handling.
  • 🔒 Built with security in mind to prevent unauthorized invite usage.
  • 🎉 Show the invitee a welcome page or role upgrade page after signing up or upgrading their role.


Installation

⚠️ Requires Better Auth v1.4.13 or newer

Install the plugin

npm install better-invite
# or
pnpm add better-invite
# or
yarn add better-invite
# or
bun add better-invite

Server-Side Setup

Start by importing invite in your betterAuth configuration.

import { invite } from "better-invite";

export const auth = betterAuth({
    //... other options
    plugins: {
        adminPlugin({
            ac,
            roles: { user, admin },
            defaultRole: "user",
        }),
        invite({
            defaultRedirectAfterUpgrade: "/auth/invited",
            async sendUserInvitation({ email, role, url }) {
                void sendInvitationEmail(role as RoleType, email, url);
            },
        })
    },
    emailAndPassword: {
        enabled: true
    }
});

Client-Side Setup

Import the inviteClient plugin and add it to your betterAuth configuration.

import { inviteClient } from "better-invite";

const client = createClient({
    //... other options
    plugins: [
        inviteClient()
    ],
});

Usage/Examples

1. Creating Invites

Authenticated users can create invite codes. You can create an invite on the client or on the server.

import { authClient } from "@/lib/auth-client";

const { data, error } = await authClient.invite.create({
  // Here you put the options
  role: "admin",
  // The invite is private, because no email is passed when creating the invite
  senderResponse: "token" // Will receive the invite token
});

if (error) {
  console.error("Failed to create invite:", error);
}

if (data) {
  // Example response: { status: true, message: "token" }
  console.log("Invite token:", data.message);
}

2. Activating Invites

When a user receives an invite code, he needs to activate it. If the user receives an email, the link they receive automatically activates the invite.

You can also activate an invite manually using the api.

import { client } from "@/lib/auth-client";

const { data, error } = await client.invite.activate({
  token,
});

if (error) {
  // Handle error (e.g., code invalid, expired, already used)
  console.error("Failed to activate invite:", error);
}

// On successful activation, a cookie named (by default) '{your-app-name}.invite-code'
// is set in the user's browser. This cookie will be used during sign-up.
console.log("Invite activated successfully.");

How it works

  • When an invite is activated, the token is saved in the user's browser cookie.
  • A hook runs after key authentication endpoints (like /sign-up/email, /sign-in/email, /verify-email, and social callbacks).
  • The hook validates the token, checks expiration and max uses, and marks the invite as used.
  • The user's role is upgraded if applicable.
  • The cookie is cleared after the invite is consumed.
  • The user is redirected to defaultRedirectAfterUpgrade to see their new role or welcome page.

Read the documentation to learn more.

Acknowledgements


This project is not associated with Better Auth