PhoenixKitUserConnections
Social relationships module for PhoenixKit — follows, mutual connections, and blocking.
Features
- Follows — One-way relationships (User A follows User B, no consent needed)
- Connections — Two-way mutual relationships (both users must accept)
- Blocking — Prevents all interaction, removes existing follows/connections
- History logging — Full audit trail for all relationship actions
- Admin dashboard — Statistics overview and module toggle
- User LiveView — Tabbed interface for managing personal connections
Installation
Add to your mix.exs dependencies:
{:phoenix_kit_user_connections, "~> 0.5"}
Requires phoenix_kit 3.10.0 or later (any core 3.x).
The module is auto-discovered by PhoenixKit at startup — no additional
configuration needed. Run mix phoenix_kit.update after adding or upgrading it:
the module owns its tables' migration chain
(PhoenixKitUserConnections.Migrations), which runs after core's.
Enable the module from the admin Modules page (or
PhoenixKitUserConnections.enable_system/0); its admin statistics page is
/admin/connections under your PhoenixKit URL prefix. The user-facing page,
PhoenixKitUserConnections.Web.UserConnections, is not routed by the module:
mount it at /profile/connections under the same prefix
(PhoenixKit.Utils.Routes.path("/profile/connections")), inside PhoenixKit's
authenticated live_session. Its tab links patch to that path, so it breaks
anywhere else.
Usage
# Follow a user
PhoenixKitUserConnections.follow(current_user, other_user)
# Request a mutual connection
PhoenixKitUserConnections.request_connection(current_user, other_user)
# Accept a connection request (only its recipient may; anyone else gets
# {:error, :not_recipient}). reject_connection/2 takes the same arguments.
PhoenixKitUserConnections.accept_connection(current_user, connection)
# Block a user (removes existing follows/connections)
PhoenixKitUserConnections.block(current_user, other_user, "reason")
# Get full relationship status
PhoenixKitUserConnections.get_relationship(current_user, other_user)
# => %{following: true, followed_by: false, connected: false, ...}
Business Rules
- Cannot follow/connect with yourself
- Cannot follow/connect if blocked (either direction)
- If A requests B while B has pending request to A, both are auto-accepted
- Only the recipient of a request may accept or reject it; only its requester may cancel it
- Blocking removes all existing follows and connections between the users
License
MIT — see LICENSE.