spapas
Phoenix presence use list only for authorized users
Hello, i want to use phoenix presence to track the users of my application but i want updates to be submitted only to superusers. i.e i don’t want to allow everybody to see who’s online. I tried implementing this by following the tutorial and adding a check on the handle_info(:after_join) of my channel like this: phxcrd/lib/phxcrd_web/channels/room_channel.ex at master · spapas/phxcrd · GitHub
I.e i’ve added this check: if socket.assigns[:perms] |> Enum.member?("superuser"), do: push(socket, "presence_state", Presence.list(socket)) to only push updates to superusers.
Is this the correct way to do it ? It seems to be working (i.e non superusers don’t receive any updates) but is this enough? could f.e somebody query the channel for updates ? i’m not very familiar with channels ![]()
TIA for any help!
Most Liked
LostKobrakai
This is my goto resource for customizing phoenix presence information propagation: https://medium.com/@alvinlindstam/phoenix-presence-for-social-networks-5fb67143f0ad
Intercepts work as well, but can become a bottleneck.
outlog
you’ll want to intercept the presence_diff message and add your conditional there as well..
intercept ["presence_diff"]
def handle_out("presence_diff", msg, socket) do
if socket.assigns[:perms] |> Enum.member?("superuser"), do: push(socket, "presence_diff", msg)
{:noreply, socket}
end
outlog
fyi: as an alternative.. you can easily inspect all websocket messages in your browser’s developer tools..
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








