Skip to main content
Version: 5.x.x

Socket Authentication

To exchange authenticated events, set up the auth parameter with authentication query params. Later on, you can change the auth value with setAuth method, which after setting up the new data will reconnect the socket server.

const token = "1234";
const socket = new Socket({ url: "ws://localhost:3000", auth: { token } });

// If token change
const newToken = "4321";
socket.setAuth(newToken); // Trigger reconnection