Phoenix.Socket and connection origin

Hi, I have a question about Sockets/Channels but couldn’t find an answer (sorry if duplicate)

I’m trying to check the origin of the socket connection. I want to limit who can use a specific channel based on their URL address (URL is not static). I’m building a Socket API of sort for live chat and want to limit chat usage for a specific customer.

Many thanks :slight_smile:

EDIT: Nope, not it…

Okay, I found a solution! (after asking ChatGPT :smiley: )
When configuring socket in endpoint, just add :uri and it will pass URI data to socket :slight_smile:

1 Like

Hey @regex.sh can you show your solution in code? I’m also super curious if you can share your chat GPT session, I think some examples of people using it for Elixir would be super cool!

I deleted ChatGPT session because it wasn’t what I asked for :confused: (but I still wouldn’t feel comfortable sharing my terrible prompting with the world :smiley: )

I still can’t find Phoenix native solution for this problem.

I “fixed” the problem with Nginx and x-headers

proxy_set_header X-Http-Origin $http_origin;

And

websocket: [
  connect_info: [:x_headers, session: @session_options]
]
1 Like