I'm working with socket.io for the first time to setup auth.
Whats the difference between using a middleware vs running a function after connection?
Ref: https://socket.io/docs/v4/middlewares/
// middleware
io.use((s, next) => {
if (isAuthed(s.request)) {
next();
} else {
next(new Error("invalid"));
}
});
vs
// after connection
io.of("/").on("connection", (s) => {
if (!isAuthed(s.request)) throw new Error("invalid");
...
});