Skip to content

How to reconnect with new JWT in handshake #4936

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

You must be logged in to vote

Or is WS authentication meant to be validated only on initial connection?

It's up to you. You can either keep the existing connection alive with an expired token, or you can either force the reconnection, with:

  • either socket.disconnect().connect(); on the client side
  • or socket.disconnect() on the server side, and then you catch the disconnect event:
socket.on("disconnect", (reason) => {
  if (reason === "io server disconnect") {
    socket.connect();
  }
  // automatic reconnection
});

See also:

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Nosfistis
Comment options

@darrachequesne
Comment options

@Nosfistis
Comment options

@pastukhvladyslav
Comment options

@darrachequesne
Comment options

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