Add a Working Team Invite System to a SaaS App
Build a real invite flow for a SaaS app so existing users can invite teammates by email, store invite records, validate tokens, accept invitations, and join the correct workspace with proper permissions.
The route
9 steps to Done
- 01
Audit the current auth and workspace model
Make the AI inspect the existing app structure before changing anything so the invite system fits the current data model and authorization rules.
Preview prompt + verify gate ▾ Hide ▴
Analyze this SaaS app and map the current auth and team structure. Identify the user table or model, workspace or organization table, membership table, role system, and any existing settings or members page. Based on the current architecture, propose the minimal set of additions needed for a working invite system: database changes, API endpoints, server actions, auth checks, pages, and components. Do not implement yet; first give me a concrete plan aligned to the existing codebase.
- ✓ The builder identifies the existing user model
- ✓ The builder identifies the workspace or organization model
- ✓ The builder identifies how roles and permissions are enforced today
- ✓ The plan names the pages or screens where invite UI belongs
- ✓ The plan includes both backend and frontend changes
- 02
Add the invite data model and migration
Create persistent invite storage with fields needed for secure invite handling.
Preview prompt + verify gate ▾ Hide ▴
Create the database schema and migration for a real invite system in this app. Add an invites table or equivalent model with: id, workspaceId, email, invitedRole, invitedByUserId, tokenHash or secure token storage, status such as pending/accepted/revoked/expired, expiresAt, acceptedAt, acceptedByUserId, createdAt, updatedAt, and any needed indexes or unique constraints. Also prevent duplicate active invites for the same workspace and email if possible. Update related ORM types and model relationships to match the existing codebase.
- ✓ An invite table or model exists in the real database schema
- ✓ Workspace, inviter, and role fields are included
- ✓ Status and expiration fields exist
- ✓ Token storage is secure or intentionally handled
- ✓ The migration runs without schema errors
- 03
Build secure invite creation on the server
Implement backend logic that creates invites only for authorized users and generates usable tokens.
Preview prompt + verify gate ▾ Hide ▴
Implement a real server-side create-invite flow in this app. Add an endpoint or server action that takes workspaceId, invitee email, and role. Validate that the current user is authenticated, belongs to the workspace, and has permission to invite. Normalize the email, check for duplicate active invites or existing membership, generate a secure unique token, set an expiration date, save the invite record, and return either a generated invite URL or the email send result. Use the app's current auth and error handling patterns.
- ✓ Unauthorized users cannot create invites
- ✓ Email input is validated and normalized
- ✓ Secure tokens are generated server-side
- ✓ Invite records are saved in the database
- ✓ Duplicate pending invites are blocked or intentionally replaced
- 04
Add the invite UI in workspace settings or members
Give admins a real interface to send invites and see immediate results.
Preview prompt + verify gate ▾ Hide ▴
Implement the frontend for sending invites in the existing workspace members or settings area. Add a form with invitee email and role selection where applicable, wire it to the real invite creation endpoint or server action, and show loading, success, and error states. If email delivery is not configured, display the generated invite link so it can be copied for testing. Reuse the app's current component and styling patterns.
- ✓ The invite form appears in the correct workspace context
- ✓ Only authorized roles can see or use it
- ✓ Submitting the form triggers the real backend flow
- ✓ Loading and error states are visible
- ✓ A real invite link or send confirmation is shown on success
- 05
Implement invite listing, resend, and revoke
Let workspace admins manage pending invites after sending them.
Preview prompt + verify gate ▾ Hide ▴
Build invite management for the workspace members area. Show pending and recent invites with email, role, inviter, status, created date, and expiration. Add server-side revoke and resend actions with proper authorization. Revoking should make the token unusable. Resending should either re-send the email or surface a fresh usable link depending on the app's setup. Refresh the UI after each action using the app's existing data fetching patterns.
- ✓ Pending invites are queried from the database
- ✓ Revoke updates the invite status persistently
- ✓ Revoked invites are no longer valid
- ✓ Resend produces a real link or send result
- ✓ The list refreshes correctly after actions
- 06
Build the invite acceptance page and token validation
Create the recipient flow that validates the invite and guides the user to sign in or sign up.
Preview prompt + verify gate ▾ Hide ▴
Implement the invite acceptance route or page for this app. It should read the invite token from the URL, validate it server-side against the stored invite record, check status and expiration, and render the correct state: valid invite, expired, revoked, already accepted, or invalid token. For a valid invite, show workspace details and an accept action. If the visitor is unauthenticated, preserve the invite context and route them through sign-in or sign-up before returning to complete acceptance.
- ✓ The token is validated server-side against stored invite data
- ✓ Invalid and expired invites show distinct messages
- ✓ The page shows real workspace and role details
- ✓ Unauthenticated users are routed into auth without losing invite context
- ✓ Already accepted invites are handled safely
- 07
Implement the final accept action and membership creation
Make acceptance actually grant access by creating or updating the workspace membership.
Preview prompt + verify gate ▾ Hide ▴
Build the real accept-invite server action or endpoint. It must require authentication, re-validate the token and invite status, ensure the authenticated user's email matches the invited email if your app requires that, create or update the workspace membership record with the invited role, mark the invite accepted with acceptedAt and acceptedByUserId, and prevent double acceptance. Use a transaction if supported so membership creation and invite status update stay in sync. Redirect the user to the correct workspace page after success.
- ✓ Accepting an invite creates a real workspace membership
- ✓ The invite status becomes accepted in the database
- ✓ The same invite cannot be accepted twice
- ✓ The user lands in the correct workspace after acceptance
- ✓ Partial failure does not leave mismatched membership and invite state
- 08
Handle edge cases and validation rules
Close the gaps AI builders often skip, including duplicate membership, mismatched emails, and expiration behavior.
Preview prompt + verify gate ▾ Hide ▴
Harden the full invite system with edge-case handling. Add clear behavior for: inviting an email already in the workspace, inviting the same email multiple times, accepting with an account whose email does not match the invited email if your app enforces matching, revoked invites, expired invites, already accepted invites, deleted workspaces, and missing inviter records if needed. Surface user-friendly error messages in the UI and make sure all checks happen server-side, not only in the client.
- ✓ Duplicate membership attempts are blocked cleanly
- ✓ Expired and revoked invites fail server-side
- ✓ Duplicate active invite behavior is intentional and enforced
- ✓ Email mismatch policy is implemented server-side if applicable
- ✓ User-facing errors are specific instead of generic
- 09
Test the end-to-end invite flow
Verify the feature works from send to acceptance for both existing and new users.
Preview prompt + verify gate ▾ Hide ▴
Run a complete end-to-end verification of the invite feature in this app. Test at least these scenarios: admin sends invite, pending invite appears, invite link opens, unauthenticated user is routed through auth, existing user accepts successfully, new user signs up and accepts successfully, membership is created in the database, revoked invite fails, expired invite fails, and double acceptance is blocked. If the app supports automated tests, add focused tests for the core server-side invite logic and acceptance flow after manual verification.
- ✓ A real invite record is created when sending
- ✓ An existing user can accept and join the workspace
- ✓ A new user can sign up and then join the workspace
- ✓ Revoked and expired invites fail correctly
- ✓ Database membership reflects accepted invites