Overview
The invite plugin provides two ways to respond to invitation events:- Hooks (
inviteHooks) - Lifecycle hooks that run before and after specific operations - Callbacks (
onInvitationUsed) - Event handler for completed invitations
src/types.ts and executed in src/hooks.ts and route files.
Invitation hooks
Configure hooks in your plugin options:Hook reference
beforeCreateInvite
Runs before an invitation is created.The endpoint context containing session, request, and other data.
- Audit logging
- Rate limiting
- Custom validation
afterCreateInvite
Runs after an invitation is successfully created.The endpoint context.
The created invitation object including:
id- Database IDtoken- Invitation tokenemail- Recipient email (if private invite)role- Target rolecreatedByUserId- Creator’s user IDexpiresAt- Expiration datemaxUses- Maximum uses allowedstatus- Invitation status
- Analytics tracking
- Webhook notifications
- Database logging
beforeAcceptInvite
Runs before a user accepts an invitation. Can modify the user object.The endpoint context.
The user accepting the invitation, including their current role.
voidorPromise<void>- No modification{ user?: UserWithRole }- Modified user object (replaces invitedUser in subsequent operations)
- Set default user attributes
- Pre-populate user profile
- Custom data transformation
afterAcceptInvite
Runs after a user successfully accepts an invitation.The endpoint context.
The accepted invitation.
The user who accepted, now with their updated role.
- Send welcome messages
- Update team membership
- Trigger onboarding flow
- Analytics events
beforeCancelInvite
Runs before an invitation is canceled.The endpoint context.
The invitation being canceled.
- Audit logging
- Validation
- Notifications
afterCancelInvite
Runs after an invitation is canceled.The endpoint context.
The canceled invitation.
- Notify affected users
- Audit logging
- Analytics
beforeRejectInvite
Runs before an invitation is rejected.The endpoint context.
The invitation being rejected.
- Logging
- Analytics
- Pre-rejection validation
afterRejectInvite
Runs after an invitation is rejected.The endpoint context.
The rejected invitation.
- Notify inviter
- Update invitation statistics
- Analytics tracking
onInvitationUsed callback
This callback runs after an invitation is successfully used and the user’s role has been updated.The user before accepting the invitation (with their old role).
The user after accepting the invitation (with their new role).
true if this was a new user account, false if it was a role upgrade for an existing user.The original HTTP request object.
Use cases
Send welcome email for new users
Send welcome email for new users
Analytics tracking
Analytics tracking
Update team statistics
Update team statistics
Trigger onboarding flow
Trigger onboarding flow
Hook execution order
Understanding when hooks run:Creating an invitation
Accepting an invitation (logged in)
Accepting an invitation (new user)
Complete example
auth.ts
Error handling in hooks
If a hook throws an error:- Before hooks: The operation is aborted and the error is returned to the client
- After hooks: The operation completes, but the error is logged (from
onInvitationUsedinsrc/utils.ts)
Next steps
Server setup
Review all configuration options
Email integration
Configure email sending for invitations