project_chat_application
project_chat_application copied to clipboard
Server crash when sending message if user not found
In server/index.js, getUser(socket.id) can return undefined (e.g., if a client emits sendMessage before completing join or after disconnect). Accessing user.room then throws and can crash the server.
Steps to reproduce
- Connect a socket.
- Do not emit join, or disconnect quickly after joining.
- Emit sendMessage.
Expected behavior
- Server validates the sender; if user is missing, it returns an error to the client and does not crash.
Actual behavior
- Server attempts to access user.room and throws, potentially terminating the process.
Affected files
- server/index.js (handler socket.on('sendMessage', ...))