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_error
event upon failureconnection
handler: the client first receives aconnect
event and then adisconnect
event