To set request header when making connection with JavaScript socket.io-client, we set the extraHeaders
property.
For instance, we write
const socket = io("http://localhost", {
extraHeaders: {
Authorization: "Bearer authorization_token_here",
},
});
to set extraHeaders
to an object with the header keys-value pairs.