Overview
TheInviteOptions type defines all configuration options available for the invite plugin. These options control invitation behavior, permissions, token generation, email sending, and lifecycle hooks.
Type Definition
Date & Time Options
A function to generate the current date. Useful for testing or custom date handling.
Number of seconds the invitation token is valid for.Default:
3600 (1 hour)Maximum age (in seconds) for the invitation cookie. This controls how long users have to complete the login flow before activating the token if they are not logged in.Default:
600 (10 minutes)Permission Options
A function or value that determines if a user can create an invite.Can be:
- A boolean value
- A function that returns a boolean (sync or async)
- A Permissions object
A function or value that determines if a user can accept an invite.
A function or value that determines if a user can cancel an invite.Note: Regardless of this option, only the user who created the invite can cancel it.
A function or value that determines if a user can reject an invite.Note: Regardless of this option, only the invitee (user whose email matches the invite email for private invites) can reject it.
Token Options
A function to generate a custom token. Required when
defaultTokenType is set to "custom".The default token type:
"token": 24-character random token (viagenerateId(24))"code": 6-character alphanumeric code (viagenerateRandomString(6, "0-9", "A-Z"))"custom": Uses thegenerateTokenfunction
Redirect Options
The default URL to redirect users to create their account.
The default URL to redirect users to sign in.
The default redirect URL after upgrading a role (or logging in with an invite).
{token} will be replaced with the user’s actual token.Custom URL pattern for invite activation. Use
{token} and {callbackUrl} placeholders, which will be replaced with their actual values.Invitation Behavior Options
Whether the inviter’s name should be shared with the invitee by default.When enabled, the person receiving the invitation will see the name of the user who created the invitation.
Maximum times an invite can be used.Default:
1 on private invites (with email) and Infinity on public invites (no email)How should the sender receive the token. Only applies when no email is provided (public invites).
"token": Return just the token string"url": Return the complete activation URL
Where should the invite redirect the user by default. Only applies when no email is provided (public invites).
Cleanup Options
Delete invitations when a decision is made (rejected or canceled).When
true, invitations are permanently deleted from the database. When false, they are marked with the appropriate status.Delete invitations after they reach max uses.
Email & Notification Options
Function to send an invitation email to the user. This function is called for both new user invitations and role upgrade invitations.Parameters:
data.email(string): Recipient email addressdata.name(string | undefined): Recipient name if availabledata.role(string): Role being assigneddata.url(string): Activation URLdata.token(string): Invitation tokendata.newAccount(boolean): Whether this is for a new accountrequest(Request | undefined): The original HTTP request object
Deprecated: Use
sendUserInvitation instead, which now receives the newAccount parameter.Send user role upgrade email.A callback function triggered when an invitation is successfully used.Parameters:
data.invitedUser(UserWithRole): User who created the invitationdata.newUser(UserWithRole): User who accepted the invitationdata.newAccount(boolean): Whether a new account was createdrequest(Request | undefined): The original HTTP request object
Schema Options
Custom schema for the invite plugin. Allows extending the default database schema with additional fields.
Hooks
Lifecycle hooks for invitation events. All hooks are optional.
Source Code Reference
Type definition:src/types.ts:5-303
Related
- invite() - Main plugin function
- Permissions Type - Permission configuration
- InviteType - Invitation data structure