Skip to content

Mimic auth option in 2.x client to do authenticate in server #4336

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

You must be logged in to vote

Hi!

but my customers still use socket.io-client 2.x (mainly to support IE 11)

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 error event in v2 was…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@qiulang
Comment options

@qiulang
Comment options

@darrachequesne
Comment options

Answer selected by qiulang
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