Skip to content

Commit

Permalink
Use connect_info
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Jun 8, 2019
1 parent ea6aa24 commit 0c5544e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion guides/presence.md
Expand Up @@ -64,7 +64,7 @@ end
We also need to change our connect function to take a `user_id` from the params and assign it on the socket. In production you may want to use `Phoenix.Token` if you have real users that are authenticated.

```elixir
def connect(params, socket) do
def connect(params, socket, _connect_info) do
{:ok, assign(socket, :user_id, params["user_id"])}
end
```
Expand Down
4 changes: 3 additions & 1 deletion lib/phoenix/token.ex
Expand Up @@ -69,7 +69,7 @@ defmodule Phoenix.Token do
defmodule MyApp.UserSocket do
use Phoenix.Socket
def connect(%{"token" => token}, socket) do
def connect(%{"token" => token}, socket, _connect_info) do
case Phoenix.Token.verify(socket, "user salt", token, max_age: 86400) do
{:ok, user_id} ->
socket = assign(socket, :user, Repo.get!(User, user_id))
Expand All @@ -78,6 +78,8 @@ defmodule Phoenix.Token do
:error
end
end
def connect(_params, _socket, _connect_info), do: :error
end
In this example, the phoenix.js client will send the token in the
Expand Down

0 comments on commit 0c5544e

Please sign in to comment.