Check valid logged in user through websocket connection

I want to send chat messages from client to server over a websocket connection.

When the websocket connection is established i want to know: who is the user?, and is the user valid logged in?

My idea is to send in the websocket packet the uf4 cookie, then i take a look in the sessions table and search for the cookie to get the specific user.

Has anyone a better idea or any suggestions?

Iam using UF 4.1 and Ratchet 0.3 for websocket connection.

Not really experienced on this front, but how is the web socket connection established? Is there some JavaScript that initiates the request/loads the (I’m assuming) widget for each user? If so you might be able to pass the information to the constructor from the Twig template itself.

To verify a user’s logged-in status through a WebSocket connection, follow these steps:

  1. Implement an authentication mechanism for the WebSocket server to verify user credentials or session information.
  2. Establish a WebSocket connection after login using traditional authentication methods.
  3. Maintain user session state by storing information on the server-side using a session management system or associating the WebSocket connection with the user’s authenticated session ID.
  4. Validate user status during communication by checking the user’s session token or retrieving session information from the server’s session management system.
  5. Handle authentication errors by terminating the connection or sending an error message. Implementation details may vary depending on the WebSocket library or framework used and authentication mechanism.