Skip to content

Instantly share code, notes, and snippets.

@marinho10
Last active April 27, 2020 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinho10/d4407b40c254f1f15dd94d341d7e0397 to your computer and use it in GitHub Desktop.
Save marinho10/d4407b40c254f1f15dd94d341d7e0397 to your computer and use it in GitHub Desktop.
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