Fileoverview

Accept Invitation Edge Function

Handles the acceptance of team invitations, creating the necessary client and site memberships for the authenticated user.

Endpoint

POST /accept-invitation

Auth

Required - JWT in Authorization header

Remarks

  • Validates invitation token, status (must be 'pending'), and expiration
  • Checks email restriction if invitation was sent to specific email
  • Prevents duplicate memberships for the same client
  • Creates client_memberships record with invited role
  • Creates site_memberships for all sites under the client
  • Updates invitation status to 'accepted' with timestamp

Example: Request body

{ "token": "abc123-invitation-token" }

Returns

200 - Success with client details (client_id, client_name, role)

Returns

400 - Invalid/expired invitation, missing token, or already a member

Returns

401 - Missing or invalid authorization header

Returns

403 - Email mismatch (invitation sent to different email)

Returns

404 - Invitation not found

Returns

500 - Internal server error