Skip to content

better-invite/better-invite

Repository files navigation

Better Invite Logo

Better Invite

A plugin for Better Auth that adds an invitation system, allowing you to create, send, and manage invites for user sign-ups or role upgrades.
Learn More Β»

Demo Β· Website Β· Issues

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.

Please consider sponsoring us

Sponsor us :)

Installation

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()
    ],
});

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

About

A plugin for Better Auth that adds an invitation system, allowing you to create, send, and manage invites for user sign-ups or role upgrades.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

51 stars

Watchers

2 watching

Forks

Sponsor this project

Packages

 
 
 

Contributors