Overview
The Better Auth Invite Plugin adds a comprehensive invitation system to your Better Auth implementation, allowing you to control user sign-ups and manage role upgrades through secure invite codes. This plugin enables you to create, send, and manage invitations for user sign-ups or role changes, giving you fine-grained control over who can access your application and what permissions they receive.Key features
Track invitations
Keep track of who created each invite and who accepted it, providing full audit trails for your user onboarding.
Flexible invite codes
Create invitation codes to control user sign-ups with support for multiple token types (default, code, or custom).
Email integration
Send invitations via email, provide shareable URLs, or generate invitation codes for manual distribution.
Role management
Automatically assign or upgrade roles when invites are used, perfect for team management.
Usage limits
Track each invitation’s usage and enforce maximum uses to prevent abuse.
Secure storage
Store tokens securely in browser cookies for seamless activation during the authentication flow.
Additional capabilities
- Multiple token types: Choose between 24-character tokens, 6-digit codes, or implement custom token generation
- Cookie-based activation: Tokens are stored securely in cookies and automatically consumed during sign-up or sign-in
- Customizable behavior: Full control over redirects, token expiration, and email handling
- Security-focused: Built with security best practices to prevent unauthorized invite usage
- Welcome pages: Show invitees a custom welcome or role upgrade page after activation
Requirements
You’ll also need:- A Better Auth instance configured with a database adapter
- Email sending capability (if using private invites sent via email)
- The admin plugin (recommended for role-based access control)
When to use this plugin
The invite plugin is ideal for:- Closed beta applications: Control who can sign up during your beta phase
- Team collaboration: Invite team members and assign roles automatically
- Role upgrades: Allow users to upgrade from free to paid tiers via invitation
- Referral systems: Track who invited whom for referral programs
- Gated communities: Ensure only invited users can create accounts
How it works
The invitation system follows a simple flow:Create an invite
An authorized user creates an invitation specifying the target role and optional email address.
Send or share
The invite is either sent via email (private) or the token/URL is shared manually (public).
Activate the invite
The recipient clicks the invite link or manually activates the token, which stores it in a cookie.
Sign up or sign in
When the user signs up or signs in, a hook automatically validates and consumes the invite.
Architecture overview
Database schema
The plugin adds two tables to your database: invite table:token: Unique invitation tokencreatedByUserId: ID of the user who created the inviteemail: Optional email for private invitesrole: Role to assign when invite is usedmaxUses: Maximum number of times this invite can be usedexpiresAt: Expiration timestampstatus: Current status (pending, rejected, canceled, used)shareInviterName: Whether to show inviter’s name to inviteeredirectToAfterUpgrade: Optional custom redirect URLnewAccount: Whether this is for a new account (private invites only)
inviteId: Reference to the inviteusedByUserId: ID of the user who used the inviteusedAt: Timestamp when invite was used
Endpoints
The plugin exposes the following API endpoints:POST /invite/create: Create a new invitationPOST /invite/activate: Activate an invite tokenGET /invite/:token: Activate invite via GET (with redirect)GET /invite/get: Get information about an invitePOST /invite/cancel: Cancel a pending invitePOST /invite/reject: Reject an invite (for invitees)
Hooks
The plugin automatically hooks into key authentication endpoints:/sign-up/email/sign-in/email/sign-in/email-otp/verify-email/callback/:id(social logins)
Next steps
Installation
Install the plugin and set up your database schema
Quick start
Get your first invite working in minutes