Skip to content

middleware vs running after connection #4249

Answered by darrachequesne
TriStarGod asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  • middleware: the client receives a connect_error event upon failure
  • in the connection handler: the client first receives a connect event and then a disconnect event

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TriStarGod
Comment options

Answer selected by TriStarGod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants