How to Restrict Socket Connection to Authenticated Users #70
-
Hello, I'm currently working on a chat application and I'm trying to ensure that only authenticated users can connect to the socket. However, I haven't found a direct way to prevent unauthorized connections. Presently, my approach involves allowing connections and then disconnecting unauthorized users, but I'd prefer a method to prevent unauthorized connections altogether. Could anyone guide me on implementing a setup where only authenticated users can establish socket connections, avoiding the need to disconnect them after they connect? Thank you for any insights or suggestions you can provide! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
What is the use case? Any connections with the public role will have the same access as whatever the role has currently with the rest api. They wouldn't be receiving any additional data. |
Beta Was this translation helpful? Give feedback.
A sample code would be something along the lines of
This middleware will run after the initial handshake takes place. Hope that helps.