Endpoint
Authentication
This endpoint supports optional authentication. It works for both:- Authenticated users (upgrades their role immediately)
- Unauthenticated users (sets a cookie and redirects to sign in/up)
Request Body
The invitation token to activate.
Where to redirect the user after signing in/up. Used when the user is not authenticated.
Response
Success Response - User Logged In (200)
When the user is already authenticated and their role is upgraded:Always
true on success.Confirmation message:
"Invite activated successfully"URL to redirect the user to after role upgrade. Uses
redirectToAfterUpgrade from the invitation or plugin options.Success Response - Sign In/Up Required (200)
When the user is not authenticated:Always
true on success.Message:
"Please sign in or sign up to continue."Action required:
"SIGN_IN_UP_REQUIRED"URL to redirect the user to for signing in/up. Uses
callbackURL from the request or defaultRedirectToSignIn from plugin options.Examples
Activate Invite (Logged In User)
Request:Activate Invite (Not Logged In)
Request:Activate Invite for New Account
Request:redirectTo points to the sign-up page.
Error Responses
Invalid or Expired Token (400)
- Token doesn’t exist in the database
- Token has expired
- Invitation has been canceled or rejected
Insufficient Permissions (400)
- User doesn’t have permission based on
canAcceptInviteoption - For private invites: User’s email doesn’t match the invitation email
No Uses Left (400)
- The invitation has reached its
maxUseslimit
Invalid Email (400)
- The logged-in user’s email doesn’t match the private invitation’s email
Behavior
For Authenticated Users
- Validates the invitation token
- Checks if token is expired or already used
- For private invites, verifies the user’s email matches
- Checks
canAcceptInvitepermissions - Updates the user’s role in the database
- Records the invitation use
- Triggers
onInvitationUsedcallback - Returns success with redirect URL
For Unauthenticated Users
- Validates the invitation token
- Checks if token is expired or already used
- Stores the token in a secure HTTP-only cookie
- Returns
SIGN_IN_UP_REQUIREDaction with redirect URL - After user signs in/up, a callback endpoint automatically activates the invitation
Invitation Cookie
When the user is not authenticated:- Cookie name:
invite_token - Max age:
options.inviteCookieMaxAge(default: 600 seconds / 10 minutes) - Attributes:
HttpOnly,SameSite=Lax,Secure(in production)
Hooks
The following hooks are triggered during this endpoint (when user is authenticated):beforeAcceptInvite: Called before accepting the invitationafterAcceptInvite: Called after the invitation is accepted successfully
Permissions
Permission is checked using thecanAcceptInvite option:
Cleanup
IfcleanupInvitesAfterMaxUses is enabled and the invitation reaches its max uses, the invitation record is automatically deleted.
Source Code Reference
Implementation:src/routes/activate-invite.ts:10-123
Logic: src/routes/activate-invite-logic.ts
Related
- Create Invite - Create a new invitation
- Get Invite - Get invitation details
- InviteOptions - Plugin configuration options
- InviteType - Invitation data structure