Imagine a SaaS app's first version of "Invite teammate." An admin enters an email, the API creates a link, and anyone who opens it joins the workspace. It works in the demo. Then the link gets forwarded to a group chat. A manager who left the company last month still has pending invites that work. Two admins invite people at the same moment on a three-seat plan, and the team ends up with four members. Someone opens an invite while signed in to their personal account and lands in the wrong place.
An invite is a small piece of access control. It deserves the same care as a password reset link.
A safe invitation flow comes down to a few rules:
- Generate a random, single-use token with an expiry, and store only a hash of it.
- Decide whether each invite is bound to an email address or deliberately open.
- Store the intended role on the invite, and check permissions again when it's accepted.
- Enforce seat limits atomically, counting pending invites.
- Revoke cleanly, including invites sent by people who have since been removed.
- Return clear, specific results from the accept endpoint, and record every step.
What an invite record holds
A single table can carry most of the design. A typical invite row holds:
- The tenant it belongs to.
- The invited email, if the invite is bound to one.
- The role the invitee will receive.
- Who sent it and when.
- A hash of the token, never the token itself.
- An expiry time.
- A status: pending, accepted, revoked, or expired, with timestamps for each change.
Keeping status explicit, rather than deleting rows, makes revocation, auditing, and "this invite was already used" messages straightforward.
The token
The OWASP Forgot Password Cheat Sheet lists the properties a reset token needs, and they apply equally to invite links. Tokens should be randomly generated with a cryptographically safe algorithm, long enough to resist brute force, stored securely, single use, and set to expire after an appropriate period.
In Node, crypto.randomBytes produces cryptographically strong random data, per the Node crypto documentation. Thirty-two random bytes, encoded for a URL, is a common choice.
Store a hash, not the token. If the invites table leaks, stored tokens shouldn't be usable. Hashing the token with SHA-256 before saving it, and hashing the incoming token to look it up, keeps the database free of working links. OWASP's Password Storage Cheat Sheet warns against fast hashes like SHA-256 for passwords, because passwords are guessable. A long random token isn't, which is why a fast hash is a reasonable fit here.
Three smaller details from the same OWASP guidance:
- Build the link from configuration, not from the request's Host header, so an attacker can't make your app email a link pointing to their domain.
- Keep the token out of referrers. OWASP recommends a Referrer Policy of
no-referreron pages that carry tokens. MDN's Referrer-Policy reference explains the options, and its privacy guide uses a reset-password page as its example of a leak. - Accept with a POST. Let the link open a page that shows the invite, and let the user confirm with a button that sends a POST. That keeps link scanners and previews from accepting invites on someone's behalf.
How long should an invite last?
There's no standard, but products give a useful range. As of November 2026:
- GitHub: organization invitations expire after seven days, per its invitation documentation.
- Auth0 Organizations: invitations default to seven days and can be set up to 30, per its API reference.
- Slack: invitations last 30 days, per its help center.
- Better Auth: its organization plugin defaults to 48 hours.
Shorter is safer, longer is friendlier. A week is a reasonable default for most B2B apps, and resending an expired invite should be one click.
Email-bound invite or open link?
Two models are common, and they suit different needs:
- Email-bound: only the person with that email can accept. Auth0's guide to inviting organization members says invited users must log in or create an account with the email address the invitation was sent to. Forwarding the link doesn't help anyone else.
- Open link: anyone with the link can join. Slack's invite links, for example, are active for 30 days and can be used by up to 400 people. That's convenient for onboarding a whole team, but the link itself becomes the credential.
WorkOS's invitation documentation shows this is a policy choice rather than a fixed rule, with different matching rules depending on the email domain. Whichever you choose, make it explicit in the data model and in the UI, so an admin knows whether they're sending a personal invite or a reusable link. For anything with elevated roles, email-bound is the safer default.
When someone accepts while signed in as someone else
This is the case most tutorials skip. A user opens an invite for dana@company.com while signed in as dana@gmail.com. If the invite is email-bound, the server must refuse, not quietly attach the workspace to the wrong account.
The React accept page should say what happened and offer the obvious ways forward: sign out and sign in with the invited email, or ask the admin to send a new invite to the address they actually use. The server check is the one that counts; the UI just explains it.
Store the role, and check again at acceptance
Save the intended role on the invite when it's created. Then check again when it's accepted:
- The inviter may have lost the right to invite. If they were demoted or removed after sending, the invite should not grant access on their authority.
- The role may no longer be allowed. Plans change, roles get removed, and some roles may require approval.
- The workspace may be different now, for example suspended or over its seat limit.
GitHub handles one version of this directly. Its documentation on removing members says that organization invitations sent by a removed member that haven't been accepted are canceled. That's a good default to copy.
Seat limits without races
Two admins invite one person each at the same moment, on a plan with one seat left. If each request counts current members, sees room, and inserts, both succeed. The count has to be checked and updated as one step.
A straightforward approach in PostgreSQL is to lock the tenant's row while you check. The explicit locking documentation describes SELECT ... FOR UPDATE, which makes concurrent transactions wait for the lock. Inside one transaction:
- lock the tenant row,
- count members plus pending invites,
- insert the invite only if there's room.
Decide whether pending invites count toward seats. Counting them prevents over-inviting, but abandoned invites can block real ones, which is another reason for expiry and cleanup. Check the limit again at acceptance, because seats can fill between sending and accepting.
Revoking invites
Admins need to cancel pending invites. Clerk's invitation documentation notes that revoking an invitation stops its link from working, and WorkOS only allows pending invitations to be revoked. Mark the row revoked rather than deleting it, so a later click gets a clear "this invite was revoked" message instead of "not found."
Re-inviting the same email should revoke any previous pending invite, so only one valid link exists per person and tenant.
The accept endpoint's contract
Specific responses make the React flow simple. RFC 9110 gives you the vocabulary:
- 404 Not Found: no invite matches this token.
- 410 Gone: the invite existed but has expired or been revoked. The RFC notes that this status is common for limited-time, promotional services.
- 409 Conflict: already accepted, or the user is already a member.
- 403 Forbidden: the signed-in user's email doesn't match an email-bound invite, or the inviter's authority no longer holds.
Return a machine-readable reason with each, and give React a screen for each case: invalid, expired, revoked, already a member, wrong account, and seat limit reached. Each screen should offer the next step, such as asking for a new invite or switching accounts.
Enumeration and spam
Invite features can leak information and send unwanted email:
- Don't reveal existing accounts. The OWASP Authentication Cheat Sheet recommends generic responses so attackers can't learn which emails are registered. "Invitation sent" should look the same whether or not the address already has an account.
- Rate-limit sending per inviter and per tenant. OWASP's forgot-password guidance warns about flooding a user's inbox; an invite form can be abused the same way.
- Treat custom messages as plain text. If admins can add a personal note, don't render it as HTML in the email, and keep it short.
- Set up email authentication. Google's sender guidelines require SPF or DKIM for all senders, and SPF, DKIM, and DMARC for bulk senders, with spam rates kept low. Invites that land in spam don't get accepted.
Keep an audit trail
Record each step: who invited whom, with what role, when it was resent, revoked, expired, or accepted, and by which account. When a customer asks "how did this person get into our workspace?", that history is the answer.
Retention and GDPR
An invite stores someone's email before they've agreed to anything, so keep it lean:
- Purge old invites. GDPR's storage limitation principle, in Article 5(1)(e) of the regulation, says personal data shouldn't be kept longer than necessary. Delete or anonymize expired and revoked invites after a set period, keeping only what your audit needs.
- Include privacy information in the invite email. Article 14 covers personal data not obtained from the person themselves. Point (3)(b) says that when the data is used to communicate with them, information should be provided at the latest at the time of the first communication. The invite email is that first communication, so link your privacy notice in it.
- Know your legal basis. Legitimate interests under Article 6(1)(f) is one possible basis for sending an invite a customer requested, but the right basis depends on your setup. Confirm it with whoever handles compliance.
Checklist
- Generate tokens with a secure random source, store only a SHA-256 hash, and expire them.
- Build links from configuration, set
no-referrer, and accept with a POST. - Pick an expiry in the range real products use, with an easy resend.
- Choose email-bound or open invites deliberately, and default to email-bound for elevated roles.
- Refuse wrong-account acceptance on the server, and explain it in the UI.
- Store the role on the invite, and re-check the inviter's rights and the role at acceptance.
- Enforce seat limits in one transaction, and check again at acceptance.
- Revoke instead of deleting, and cancel invites sent by removed members.
- Return 404, 410, 409, or 403 with a reason, and give React a screen for each.
- Respond generically, rate-limit sends, and keep custom messages plain text.
- Authenticate your email with SPF, DKIM, and DMARC.
- Audit every invite event.
- Purge old invites and include privacy information in the invite email.



