socket.io-client-dart
socket.io-client-dart copied to clipboard
Event connect_error does not trigger when a middleware fails in the server
Hi, could you help me with the next issue, I have the following code in my server and client:
//server - javascript
this.io.of('/chat').use(isAuth).on('connection', (socket) => SocketsChat(socket, this.io));
//isAuth - javascript
export const isAuth = async (socket:Socket, next:SocketNext) => {
const token = socket.handshake.auth.token;
try {
const authUser = await verifyJWTUser(token);
const newToken = await generateJWT(authUser.id);
socket.data = {authUser, newToken};
next();
} catch (error) {
console.log('error: ', error);
next(new Error('Unauthoraized'));
}
}
//client - dart flutter
socket.on('connect_error', (e) async {
print(e);
socketError = 'Error from socket backend';
socket.disconnect();
});
When i intentionally send a invalid token, the middleware fails and the server does not connect, but in the client this event is not listened, i try with the method socket.onConnectionError and neither, when i try the same with a javascript as client this works perfectly, can you check this please, thanks a lot!
Hey is there a solution for this yet? What's the progress so far?
have the same problem, anyone have a solution?
socket.on('error', (data) => print("error $data"));
when you use it like this, the message is captured