I did step by step like docs said. Raising :error provides to logs in terminal every second, at first glance i refactored to this:
user_socket.ex
def connect(%{"token" => token}, socket, _connect_info) do
case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
{:ok, user_id} ->
{:ok, assign(socket, :user_id, user_id)}
{:error, _reason} ->
{:ok, socket}
end
end
user_channel.ex
def handle_info(:after_join, socket) do
case socket.assigns do
%{user_id: user_id} ->
track_user_presence(user_id, socket)
push(socket, "presence_state", Presence.list(socket))
{:noreply, socket}
_ ->
{:noreply, socket}
end
end
And now only log appears in terminal if user is authenticated and connected.
I’ll be working on updating status topic, and I have an issue that started to appear after using sockets/channels - I opened another topic about that, but still is missing responses ;D
Thanks for big help once again
Update: I figured out, that I can use case statement in def join to omit sending process.