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
- π€ 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.
Install the plugin
npm install better-invite
# or
pnpm add better-invite
# or
yarn add better-invite
# or
bun add better-inviteStart 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
}
});Import the inviteClient plugin and add it to your betterAuth configuration.
import { inviteClient } from "better-invite";
const client = createClient({
//... other options
plugins: [
inviteClient()
],
});- 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
defaultRedirectAfterUpgradeto see their new role or welcome page.
Read the documentation to learn more.
- Inspired in the invite system from Max.
This project is not associated with Better Auth