probil/vue-socket.io-extended

Cannot pass query info using Socket.io client/server v3

vitarmoni opened this issue · 2 comments

Hi, in socket.io client v3 they changed "query" to "auth". I've updated both server and clients.

I used to use this before opening connection: this.$socket.client.io.opts.query={foo:var} now in node clients changing "query" by "auth" it works like a charm.

But using vue-socket.io-extended with socket.io server v3 is not receiving that foo:var in auth. Also tried to write this: this.$socket.client.io.opts.auth={foo:var} without success.

Any clue? Thanks in advance!

Yo did you have any luck with this problem ? I'm also trying to pass data on client connection but can't seem to figure out how to do it with extended...

Thanks!

@vitarmoni Your questions is not directly related to the vue-socket.io-extended but to the socket.io-client. vue-socket.io-extended doesn't do anything related to the connection - it just uses socket you've configured in your code.

Anyway, here is what you can use in order to help you to fix the issue. There were some breaking changes in v3. One of the them was separating query parameters used by manager from parameters of CONNECT packet. In v3 query is still available but it's only passed to the query parameter of the url, while auth is sent with CONNECT packet

If you have this.$socket.client.io.opts.auth={foo:var} to access auth parameters on server you need to use this syntax instead:

io.on("connection", (socket) => {
  const { foo } = socket.handshake.auth;  // foo from auth params (`CONNECT` packet)
  const { foo } = socket.handshake.query; // foo from query params (url)
});

If you are doing authentication I'd suggest to stick to auth

Take a look here:
https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#No-more-implicit-connection-to-the-default-namespace