Last active
April 27, 2020 18:26
-
-
Save marinho10/d4407b40c254f1f15dd94d341d7e0397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def connect(%{"token" => token}, socket) do | |
with {:ok, user_id} <- | |
Phoenix.Token.verify(PhoenixAbsintheAuthenticatedSubscriptionsWeb.Endpoint, "user sesion", token, | |
max_age: 86_400 | |
), | |
%Accounts.User{} = current_user <- Accounts.lookup_user(user_id) do | |
socket = | |
Absinthe.Phoenix.Socket.put_options(socket, | |
context: %{ | |
current_user: current_user | |
} | |
) | |
{:ok, socket} | |
else | |
_ -> | |
:error | |
end | |
end | |
def connect(_, _), do: :error | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment