W019: Leave organization
Removes the caller's own membership from the current org. If the caller is the last owner, the org is closed (purged).
Steps
- Verify membership. Load the caller's
organization_usersrow for the org; 404 if absent. - Last owner closes the org. If the caller is an
ownerand the only active owner, cascade-purge the organization (all tenant data, memberships, and the org row) and return{ deletedOrg: true }. - Otherwise remove the membership. Delete the caller's
organization_usersrow and return{ deletedOrg: false }.
Returns
{ deletedOrg } — true when the org was purged because the caller was the last owner.
Business rules
- Self-service. A member leaves without needing an admin to remove them.
- Last owner closes the org. Rather than orphaning an owner-less org, the last owner leaving deletes it (consistent with account deletion).
Errors
NotFoundError. Caller is not a member of this org.