Replies: 1 comment
|
There are two separate issues to isolate: transport failure and authentication refresh. Send credentials through const socket = io(API_URL, {
transports: ["websocket"],
auth: { token: accessToken },
autoConnect: false,
});io.use((socket, next) => {
try {
socket.user = verify(socket.handshake.auth.token);
next();
} catch {
next(new Error("unauthorized"));
}
});When the token changes, update socket.auth = { token: refreshedToken };
socket.connect();Do not add a second manual exponential-retry loop on top of Socket.IO’s built-in reconnection until the root cause is known; the two loops can create duplicate connection attempts. Handle If WebSocket-only fails, check the actual URL scheme, TLS certificate, proxy upgrade headers, and server/client Socket.IO version compatibility. Temporarily enable both transports and inspect Also remove every handler with the same function reference during React cleanup; |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello!
I am trying to properly set up a socket.io service in my React Native app, coupled with the socket configuration done on NodeJS.
As a note - we are using JWT authentication to authenticate the socket.io instance/connection request.
I am sometimes getting
XHR poll error, especially I think when the JWT expires and tries to re-set it?Can you help me please in looking if what I have created, is ok? Sharing here both the React Native ts file and also the NodeJS configuration. I am expecting this to not "fail" if not needed.
Thank you a lot!
A part of the NodeJS Config:
A part of the React Native side:
All reactions