Browse documentation

invites

What it does

The registration and membership endpoint. Public actions probe the system (first user, domain match, invite-token validation); authenticated actions complete registration, create/revoke/re-send invites, approve or deny join requests, and manage account members. Invitees are people rows in invited/pending status carrying invite_* fields in data.

Route and methods

/.netlify/functions/invites, reachable as /api/invites (/api/* → /.netlify/functions/:splat). The outer handler is a createPublicHandler dispatching only on ?action= — there is no HTTP-method check, so GET and POST both reach every action (write actions still need a JSON body):

?action=AuthPurpose
check-first-userpublic{ is_first_user } — true when people is empty
check-domainpublicdomain→account match for registration routing
validate-tokenpublicinspect an invite token (?token=)
complete-registrationauthenticatedplace the caller via complete_registration_placement RPC
create-inviteaccount admincreate an invited people stub + invite URL
list-invitesauthenticatedlist pending invites, account-scoped
revoke-inviteaccount admindeactivate an invited person
reinviteaccount adminrotate token + expiry on invited/inactive person
block-inviteaccount adminstamp invite_blocked_at on a person
approveaccount adminactivate a pending join request
denyaccount admindeactivate a pending join request
list-members*_adminlist account members (via admin-data)
update-member*_adminchange full_name / role_slug
deactivate-member*_adminset status inactive

Unknown action → Unknown action: <action>.

Authentication

Mixed. The dispatcher is public (createPublicHandler), so anonymous reaches the three probe actions. Every other action requires an authenticated principal — each inner handler re-checks principal.id !== 'anonymous' and throws Authentication required (a plain Error, so it surfaces as HTTP 500, not 401).

"Account admin" (requireAccountAdmin) means: principal permissions include system, or roles include system_admin, or any *_admin role and principal.accountId equals the target account. Member actions (list-members, update-member, deactivate-member) accept system permission or any *_admin role (canManageMembers) plus the same account check.

Request contract

check-domain (query): email — must contain @. Personal-mailbox domains (gmail, yahoo, hotmail, outlook, icloud, protonmail, etc.) always return { match: false }; otherwise matches when an active people row exists with @<domain>.

validate-token (query): token. Looks up a people row in invited/pending status with data.invite_token = <token>.

complete-registration (body): app and path required; account_name, email optional. path values are resolved by the RPC (e.g. new_account triggers extra account_create rate limits).

create-invite (body): email, account_id, role_slug required; full_name, base_url, app optional. role_slug: 'system_admin' is refused, as is any role whose is_system flag is true or that is absent from the app's invitation.allowed_roles/registration.roles allowlist (when the app declares one).

revoke-invite / reinvite / block-invite / approve / deny (body): person_id (+ base_url for reinvite).

list-invites (query): account_id (system users may pass any; non-system callers are forced to their own account and must hold an *_admin/system_admin role or system permission on it), role_slugs (comma-separated).

list-members (query/body): account_id (defaults to the caller's). update-member (body): person_id, full_name, role_slug. deactivate-member (body): person_id.

Response contract

Standard { data, error, meta } envelope.

  • check-first-user → { is_first_user: boolean }.
  • check-domain → { match } — the boolean only; returning account_id powered cross-tenant IDOR and was removed (wildcard metachars in domain are also rejected).
  • validate-token → { email, full_name, account_name, role_name, kind }.
  • complete-registration → { status, account_slug, role_slug?, next? } from the RPC placement.
  • create-invite → { id, token, invite_url, expires_at, email_sent }.
  • reinvite → { token, invite_url, expires_at }.
  • list-invites → array of { id, email, full_name, status, kind, expires_at, blocked_at, created_at, account, role }.
  • revoke-invite/block-invite/approve/deny → { success: true }.
  • list-members → { data: [...] }; update-member/deactivate-member → { success: true, data }.

Side effects

  • create-invite/reinvite write people rows (via admin-data create for the stub): data.invite_token (16-char alnum), invite_kind: 'invite', invite_expires_at (now + 7 days), invite_attempts: 0, invite_blocked_at, invite_invited_by.
  • invite_url = <base>/register?t=<token>; base_url is honored only for localhost or origins in APP_BASE_URL/ALLOWED_ORIGINS, otherwise falls back to APP_BASE_URL.
  • create-invite sends email through integration-outbound when an active invite-email (preferred) or transactional-email integration exists; config.templates.invite subject/html support {{to_name}}, {{invite_url}}, {{account_name}}, {{expires_at}} placeholders, with a built-in HTML fallback.
  • complete-registration calls the service-role complete_registration_placement RPC (the only writer of account_id/role_id placement), then recordRegistrationGeo + registration.completed log.
  • checkRegistrationBlocklist (email, email domain, IP) runs before placement; checkRateLimit enforces registration and account_create (person + IP keyed), invite_create, and invite_email (account keyed).
  • emitLog writes invite.created, invite.revoked, invite.reinvited, invite.approved, invite.blocked, invite.denied, member.updated, member.deactivated.
  • Member actions delegate to admin-data list/update internally, so admin-data logging and trigger firing apply there too.

Errors

ConditionHTTPMessage
Anonymous on a gated action500Authentication required
Not an account admin500Insufficient permissions — *_admin role required for this account (and member variants)
Missing required fields500email, account_id, and role_slug are required / app and path are required / person_id is required / Token is required / Valid email is required
Unknown action500Unknown action: <action>
system_admin or system role requested500Role '<slug>' is not permitted in this context / Role '<slug>' not found
Duplicate email+account500A person with this email already exists or has a pending invite for this account
Bad/used token500Invite not found or already used
Blocked invite500This invite link has been blocked. Please contact the administrator.
Expired invite500This invite link has expired. Please request a new one.
≥5 failed attempts500Too many failed attempts. This invite has been blocked.
Registration blocklist hit403This registration is not eligible. Contact support if you believe this is an error.
Rate limit429RateLimitError envelope fields (action, limit, retry_after)
RPC placement failure400RPC message or Registration placement failed
Wrong state500Invite not found or already processed / Person is not in a reinvitable state / Access request not found or already processed

Agent notes

  • First-user bootstrap is not here — the Postgres handle_new_auth_user trigger grants system_admin on the very first signup. check-first-user only reports whether people is empty.
  • Invite tokens live on people.data.invite_token; revoke clears the token and deactivates; reinvite rotates it (invited or inactive rows only); validate-token enforces expiry, invite_blocked_at, and the 5-attempt ceiling.
  • approve/deny target status = 'pending' rows — the join-request path — while revoke-invite targets invited/pending.
  • update-member can only assign roles allowed by the target account's owned apps (invitation.allowed_roles/registration.roles in apps.config), and never system_admin or is_system roles.
  • list-invites is an authorization boundary: non-system callers are pinned to their own ctx.accountId (a caller-supplied account_id is ignored) and must pass requireAccountAdmin — a system permission, system_admin, or any *_admin-suffixed role on that account. revoke-invite, reinvite, block-invite, approve, and deny require the same admin check on the target person's account.
  • Registration never trusts client claims: the placement RPC derives account and role server-side from the app's registration config.

Framework documentation — Verified November 20, 2026 · source revision 666f107.

Was this page helpful? Ask a question · Report a documentation problem