Overview
The Platform API provides two types of invitations:- Company Invites - Platform admin invites users to create new companies
- Member Invites - Company members invite users to join existing companies
Company Invites
Purpose
Company invites allow platform administrators to invite specific users to create new companies. This is one of three ways to create a company:Admin Invite
Admin creates invite → User accepts → User creates company
User Request
User requests → Admin approves → User creates company
Direct Creation
User with
companies.create permission creates company directlyCompany Invite Model
CompanyInvite Structure
issuedByAdmin: Platform admin who created the inviteusedByUser: User who accepted the invite (set when used)createdCompany: Company created from this invite (1:1 relationship)
Company Invite Flow
Admin Creates Invite
Platform admin generates an invite for a specific email:The system:
- Generates a secure 32-byte random token
- Hashes the token with bcrypt (only hash is stored)
- Sets expiration date (configurable, typically 7-14 days)
- Returns the plain token to send to the user
User Registers
User creates an account, providing the invite token:The system validates:
- Token hash matches
- Email matches invite email
- Invite status is
PENDING - Expiration date hasn’t passed
Company Invite Statuses
- PENDING
- USED
- EXPIRED
- REVOKED
Initial state when invite is created.
- Invite can be used by the recipient
- Token is valid (not expired)
- Admin can revoke if needed
Member Invites
Purpose
Member invites allow authorized company members to invite users to join their company. This is the primary way to add new members to existing companies.Member Invite Model
CompanyMemberInvite Structure
company: The company the user is being invited toissuedByUser: Company member who created the invite (requires permission)usedByUser: User who accepted the invitedefaultRole: Role to assign when invite is accepted (falls back to company default role)
Member Invite Flow
Member Creates Invite
An authorized company member invites a user by email:Validation:
- Issuer has permission to invite members
- Email is not already a member
- No pending invite exists for this email
- Default role belongs to this company (if provided)
User Receives Notification
The invited user receives an email with a link:If the user already has an account, they can also see the invite in their dashboard:
Direct Member Addition
Internally, members can also be added directly without the traditional invite email flow:status: INVITED and sends a real-time notification:
Invitation Security
Token Generation
Both invite types use the same secure token pattern:- Plain tokens never stored in database
- Database breach doesn’t expose usable tokens
- Tokens are 256-bit entropy (2^256 possibilities)
- Bcrypt is slow and resistant to brute-force
Token Validation
When a user provides a token, validation follows these steps:Expiration Policy
Expiration dates are configurable via environment variables:.env
Real-Time Notifications
When a member invite is created, the system sends a real-time notification via Server-Sent Events (SSE):Best Practices
Validate Permissions
Always verify that the user creating an invite has the appropriate permission (e.g.,
members.invite).Check for Duplicates
Before creating a member invite, verify that the user isn’t already a member and doesn’t have a pending invite.
Set Reasonable Expiration
Balance security (shorter expiration) with user convenience (longer expiration). 7 days is typically appropriate.
Provide Clear Messaging
Include helpful context in invite emails: who invited them, what company, what role they’ll have.
Handle Edge Cases
What happens if a user declines, then is re-invited? Or if an invite expires while the user is registering?
Audit Invite Actions
Log who created, accepted, declined, and revoked invites for security and compliance tracking.
Clean Up Expired Invites
Run periodic jobs to update expired invites and optionally delete old invites after 90+ days.
Rate Limit Invites
Prevent abuse by limiting how many invites a user can send per day/hour.
Related Concepts
Multi-Tenancy
Learn about company creation and the tenant model
Memberships
Understand how invitations create memberships
RBAC
See how default roles are assigned during invitation