Mimic auth option in 2.x client to do authenticate in server #4336
-
The My server uses socket.io 4.2 and uses middleware to authenticate as here suggests https://socket.io/docs/v4/middlewares/#sending-credentials, but the problem is that the 2.x client does not have So deal with that, I add these 2 steps in my codes,
So far it seems to work. But I was wondering is there a better way to do authentication ? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi!
Socket.IO 3.x and above should support browsers down to IE9, isn't that the case for you? Reference: https://socket.io/docs/v4/client-installation/#browser-support The problem with the query option in v2 is that it was sent in both the query parameters and during the Socket.IO handshake. A cleaner way to do this in v2 would be the following: import { Manager } from "socket.io-client";
const manager = new Manager(server, {
transports: ["websocket"]
);
const socket = manager.socket("/", {
query: {
token,
uid
}
});
socket.on("error", () => {
// authentication error
}); The Reference: https://socket.io/docs/v2/namespaces/#handling-middleware-error |
Beta Was this translation helpful? Give feedback.
Hi!
Socket.IO 3.x and above should support browsers down to IE9, isn't that the case for you?
Reference: https://socket.io/docs/v4/client-installation/#browser-support
The problem with the query option in v2 is that it was sent in both the query parameters and during the Socket.IO handshake.
A cleaner way to do this in v2 would be the following:
The
error
event in v2 was…