middleware vs running after connection #4249
-
| 
         Hi, Ref: https://socket.io/docs/v4/middlewares/ vs I asked this question on stackoverflow but no one answered.  | 
  
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
| 
         Hi! Technically, there is no difference, the underlying connection (HTTP long-polling or WebSocket) is already established. That being said, middlewares are the best place to check if the user is authenticated/has sufficient permissions (before the connection at the Socket.IO level). I guess it makes more sense from a client point of view: 
  | 
  
Beta Was this translation helpful? Give feedback.
Hi! Technically, there is no difference, the underlying connection (HTTP long-polling or WebSocket) is already established.
That being said, middlewares are the best place to check if the user is authenticated/has sufficient permissions (before the connection at the Socket.IO level). I guess it makes more sense from a client point of view:
connect_errorevent upon failureconnectionhandler: the client first receives aconnectevent and then adisconnectevent