Skip to content

Instantly share code, notes, and snippets.

@shankardevy

shankardevy/user_socket.ex Secret

Last active Aug 19, 2017
Embed
What would you like to do?
defmodule MangoWeb.UserSocket do
use Phoenix.Socket
## Channels
channel "pos", MangoWeb.BotChannel
## Transports
transport :websocket, Phoenix.Transports.WebSocket
def connect(%{"token" => token}, socket) do
case Phoenix.Token.verify(socket, "socket_login", token) do
{:ok, user_id} ->
socket = assign(socket, :user_id, user_id)
{:ok, socket}
{:error, _} ->
:error
end
end
def id(_socket), do: nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment