diff options
Diffstat (limited to 'shardweb/lib/shard_web/channels/user_socket.ex')
-rw-r--r-- | shardweb/lib/shard_web/channels/user_socket.ex | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/shardweb/lib/shard_web/channels/user_socket.ex b/shardweb/lib/shard_web/channels/user_socket.ex index 4fb76dc..a3aa1a5 100644 --- a/shardweb/lib/shard_web/channels/user_socket.ex +++ b/shardweb/lib/shard_web/channels/user_socket.ex @@ -1,6 +1,8 @@ defmodule ShardWeb.UserSocket do use Phoenix.Socket + require Logger + ## Channels channel "room:*", ShardWeb.RoomChannel @@ -19,8 +21,18 @@ defmodule ShardWeb.UserSocket do # # See `Phoenix.Token` documentation for examples in # performing token verification on connect. - def connect(_params, socket) do - {:ok, socket} + def connect(params, socket) do + case Base.decode16(params["pk"]) do + {:ok, pk} -> + if Shard.Keys.have_sk? pk do + socket = assign(socket, :pk, pk) + {:ok, socket} + else + Logger.warn("Invalid pk at user_socket.connect... #{params["pk"]}") + :error + end + _ -> :error + end end # Socket id's are topics that allow you to identify all sockets for a given user: |