Channels have the authorized?
function, and I would like to pass the generated local token when joining the channel so that I can verify user's role, like this:
const data = { token: localStorage.getItem('phoenixAuthToken') };
channel.join(data).receive('ok', (response) => {
...
});
});
However, in my channel setup, I don't seem to receive anything from client on join:
def join("settings", payload, socket) do
IO.inspect(payload)
if authorized?(payload) do
{:ok, socket}
else
{:error, %{reason: "unauthorized"}}
end
end
IO.inspect(payload)
is just %{}
. What I'm doing wrong here? Is it even possible to receive the message when joining the channel?
.channel()
, e.g.channel = socket.channel("foo", { token: ... })
and then just dochannel.join()
. – Dogbert