I’m looking for a way to forcibly close a Phoenix socket (the entire socket, not just one channel) when a user account is deleted. Consider the following simplified example:
defmodule Main.UserSocket do
use Phoenix.Socket
def connect(%{"login_token" => token}, socket) do
with {:ok, user} <- SessionLogic.verify_login_token(token) do
{:ok, assign(socket, :user, user)}
else
_ -> :error
end
end
def connect(_params, _socket), do: :error # no unauthenticated sockets
end
So we disallow any socket creation unless we can verify that there is a valid token associated with a valid user.
Suppose while the socket is open, we get notice that the user has been deleted (i.e. no longer valid in the system). I’m looking for a way to cause this socket to be immediately closed upon receipt of that notice. There doesn’t seem to be any of the GenServer
infrastructure here, as there is in the channel case. Am I missing something?