Symfony Websockets: Logged User always returns anonym within Topic Symfony Websockets: Logged User always returns anonym within Topic symfony symfony

Symfony Websockets: Logged User always returns anonym within Topic


As this is now clear, the explanation resides in HTTP cookies limitations. Find more details here: http://www.cookiecentral.com/faq/#4.3

"The main limit on retrieving a cookie is that you can only retrieve cookies that are valid for the document your script resides in. That is, a script on www.myserver.com cannot read cookies from www.yourserver.com."

Also, I suggest you ensure running your websocket server on the "localhost" domain to access your website using "localhost". Doing so, both domains will still be in accordance.

As a question to myself, I have never checked if accessing the website by its address (127.0.0.1) and having the websocket server running on "localhost" trigger the same issue. Anyway, to answer you, no, this should not reproduce once in prod, as soon as you have the right domain (not ip).

However, the answer from Thomas is not right, you cannot run both servers on the same port, as it is the definition for ports (one port, one service/process): https://en.wikipedia.org/wiki/Port_%28computer_networking%29 .


In order to share session between web app and websocket, both must be running on the same domain and the same port, otherwise the cookie will not be sent by the browser

Web app: http://www.exemple.com:80Websocket: ws://ws.exemple.com:80

and the cookie must be configured for domain exemple.com (without any subdomain)

It seems that your config is setup for port 8081 for the websocket when your webserver is running on port 8000

Hope this helps