Throwing error in `onConnect` does not terminate websocket connection
Description
According to the docs the way to do authentication is to throw an error in the onConnect callback if authentication checks fail.
When throwing an error (or rejecting the returned Promise), the connection to the client will be terminated.
Steps to reproduce the bug Steps to reproduce the behavior:
- Create a minimal repo (might be nice if we had one of these ready for bug reports)
- Throw an error in
onConnectand nothing else - Open client in two browsers
- Awareness and state is transferred between browsers
https://github.com/ueberdosis/hocuspocus/blob/main/packages/server/src/Hocuspocus.ts#L190
^ This line is never called.
Expected behavior
The connection should be terminated.
~It should also not be possible for state to transfer between unauthenticated clients at all, messages received before authentication has completed should probably be held in a queue and emitted once onConnect has resolved.~ edit: seems like this was the intended behavior
Seems like the error is caught here, so the catch mentioned above is never triggered.
https://github.com/ueberdosis/hocuspocus/blob/629704add7ea4210e56b87b2c6b7b361f4e4e673/packages/server/src/Hocuspocus.ts#L316-L321
Yep, there is already issue here #140
I had to downgrade to v58 as it works there but not working properly in v59 and v60