project_chat_application icon indicating copy to clipboard operation
project_chat_application copied to clipboard

The Server Crashes on account of Duplicate user sending the message.

Open Dev-Sec0901 opened this issue 4 years ago • 1 comments

The code in Chat.js on client-side, sends an error when it finds a duplicate username, but that can be passed by pressing ok, as it is an alert, see code for reference

socket.emit('join', {name, room}, (error) => { if(error){ alert(error); } }); }, [ENDPOINT, location.search]);

Now on the server-side, a duplicate user has no properties like user.name or user.room so that remains undefined. Solution: By not letting the duplicate user enter into the room, it will also be a potential solution to the problem:

io.to(user.room).emit('message', {user: user.name, text: message}); ^

TypeError: Cannot read property 'room' of undefined.

Dev-Sec0901 avatar Aug 23 '20 22:08 Dev-Sec0901

There is a bug in the code, if the duplicate user clicks 'ok' on the popup 'Username is already taken', and sends a message in the room, the server crashes, as it is an alert (refer to the code below): socket.emit('join', {name, room}, (error) => { if(error){ alert(error); } }); }, [ENDPOINT, location.search]);

Solution: I've made an alert that lasts as long as error lasts, so someone with a similar username won't ever be able to enter.

socket.emit('join', {name, room}, (error) => { if(error){ do{ alert(error + " Go back, & please take another Username"); }while(error); } }); }, [ENDPOINT, location.search]);

It works perfectly fine.

Dev-Sec0901 avatar Aug 24 '20 13:08 Dev-Sec0901