phoenix-channels-essentials
Installation
SKILL.md
Phoenix Channels Essentials
For non-LiveView real-time features: mobile clients, SPAs, external APIs, inter-service communication.
RULES — Follow these with no exceptions
- Always authenticate in
connect/3— channels bypass the Plug pipeline; tokens must be verified in the socket - Authorize in
join/3— verify the user can access the requested topic before allowing the connection - Use
handle_infor client-to-server,pushfor server-to-client,broadcastfor server-to-all — never confuse the direction - Keep channel modules thin — delegate business logic to context modules; channels are the transport layer
- Use Presence for tracking connected users — don't roll your own presence tracking; Phoenix.Presence handles node distribution
- Return
{:reply, :ok, socket}or{:reply, {:error, reason}, socket}fromhandle_in— don't silently drop messages
Socket Authentication
Channels bypass the Plug pipeline, so session-based auth doesn't work. Use token-based authentication.