Invites
Invites let a signed-in user ask someone to join your app by email. Forte sends the invite email from your project's sender. When the invited person signs up with that email address, Forte records who invited them on the new user.
Use invites for referral programs, "invite a teammate" flows, or any feature where you want to know which existing user brought in a new one.
Invites use Forte's client-side API. The inviting user creates, lists, and revokes their own invites with their session. A Forte Service frontend can use the first-party /_forte path. Mobile apps and server-side code must pass the user's session token as a bearer token. Authenticate these calls with the user's session, not FORTE_API_TOKEN.
How invites work
- A signed-in user calls
createUserInvitewith the email address of the person to invite. Forte stores a pending invite and sends the invite email. - The invited person signs up for your app with the same email address, through email registration or Google sign-in. Forte matches the email address without regard to case.
- Forte creates the new user with
invitedByUserIdset to the inviter's user ID and marks the invite as accepted.
The invite email does not carry a token. Forte matches the invite to the new user by email address alone, so the invited person can sign up from any page of your app. If they sign up with a different email address, Forte does not link them to the inviter.
A pending invite expires 30 days after it's created. Forte then removes it, and a later sign-up with that email address is not linked to the inviter.
Invite a user
This example invites a user from a Forte Service frontend. The optional customAttributes map passes values to the invite email template. Here, signupUrl gives the email a link to your sign-up page.
import { ForteClient } from "@forteplatforms/sdk";
const forte = new ForteClient({ baseUrl: "/_forte" });
const invite = await forte.users.createUserInvite({
projectId,
createUserInviteRequest: {
email: "teammate@example.com",
customAttributes: {
signupUrl: "https://app.example.com/signup",
},
},
});
console.log(invite.inviteId, invite.expiresAt);Forte rejects the invite when the email address already belongs to a user in the project, or when that address already has a pending invite from any user. An email address can have only one pending invite at a time.
Customize the invite email
Forte's default invite email names your project but doesn't link anywhere. Customize it under Settings → Notifications, in the Invite tab, so the email tells the invited person where to sign up.
The invite template accepts these variables:
| Variable | Value |
|---|---|
{{projectName}} | Your project's name |
{{contactValue}} | The invited email address |
{{inviterName}} | The inviting user's full name, or empty if they haven't set one |
| Any custom attribute key | The value passed in customAttributes for this invite |
For example, this body uses the signupUrl attribute from the earlier example:
<p>{{inviterName}} invited you to join {{projectName}}.</p>
<p><a href="{{signupUrl}}">Create your account</a></p>Custom attributes follow these limits:
- Up to 20 attributes per invite.
- Keys start with a letter and contain only letters, digits, and underscores, up to 64 characters.
- Values contain no control characters, up to 500 characters.
- Keys can't reuse a built-in variable name such as
projectNameorinviterName.
A template variable with no matching attribute renders as an empty string.
On the sandbox email sender, Forte always sends its default invite email and ignores your customization. Your Invite template applies once your project sends from your own domain. Each invite also counts toward the sandbox sender's daily email limit.
List and revoke invites
A user can list the invites they sent that haven't been accepted yet, newest first. They can revoke any of those invites, which deletes it. A later sign-up with that email address is then not linked to them.
const { invites } = await forte.users.listUserInvites({ projectId });
for (const invite of invites) {
console.log(invite.inviteId, invite.inviteeEmail, invite.expiresAt);
}
await forte.users.revokeUserInvite({ projectId, inviteId: invites[0].inviteId });Only the user who created an invite can see or revoke it. Revoking an invite that another user created, or one that was already accepted, returns 404.
Track who invited whom
Each user created from an invite has invitedByUserId set to the inviter's user ID. Read it from your backend with the Projects user methods to credit referrals or show who brought in a teammate.
Forte also records invite activity in each user's audit trail:
| Event | Recorded on |
|---|---|
USER_INVITE_CREATED | The inviter, with the invite ID and invited email address |
USER_INVITE_REVOKED | The inviter, with the invite ID and invited email address |
USER_INVITE_ACCEPTED | The new user, with the invite ID and the inviter's user ID |
Errors
| Error | Cause |
|---|---|
409 USER_ALREADY_EXISTS | A user in the project already has this email address |
409 INVITE_ALREADY_EXISTS | This email address already has a pending invite |
400 CUSTOM_ATTRIBUTE_RESERVED_KEY | A custom attribute key reuses a built-in template variable name |
402 SANDBOX_EMAIL_QUOTA_EXCEEDED | Sandbox sender only: your account reached its daily sandbox email limit (UTC). Forte doesn't create the invite |
404 | On revoke: the invite doesn't exist, belongs to another user, or was already accepted |
Next steps
- Customize your project's built-in notification messages
- Set up Authentication methods for invited users
- Review user activity in Administration