New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Middleware(.use) does not emit connect when using a custom namespace #3082
Comments
Hi! How are you initializing the client? The following seems to work for me: io.use((socket, next) => {
console.log('(default) middleware running...');
next();
}).on('connection', socket => {
console.log('(default) client connected');
});
// Following works, but client does not receive 'connect' or 'connection':
io.of('/admin').use((socket, next) => {
console.log('(admin) middleware running...');
next();
}).on('connection', socket => {
console.log('(admin) client connected');
});
// client
const socket = require('socket.io-client')('http://localhost:3000/admin');
socket.on('connect', onConnect);
function onConnect(){
console.log('connect ' + socket.id);
} Output (fiddle):
|
No it is not working for me. Full code, working example: Server:
Client:
If i remove the middleware i can connect to both. If i add the middleware to admin only, i get no connect event on default namespace nor /admin. Server shows everything correctly:
|
Nothing? :( |
@MickL Any updates on this? It comes down to following scenarios:
|
No i used a workaround. Instead of:
I wrote:
I spent a lot on this and it seems like the client does connect to the server but the client does not get the connection event. |
I guess this can work. But it's a shame that we can't use middleware properly for its intended use. |
@darrachequesne The example you provided and tested on is not as per reported issue. You need to remove the middleware from the default namespace and then try to connect. Like this:
Now it should fail. Cheers. |
@JanisRubens Thanks for the detailed report 👍 , I was eventually able to reproduce. Fixed by #3197 |
I am still facing this! |
+1 |
@adeelhussain @ElioTohm which version are you using? Are you able to reproduce the case with the fiddle? |
using socketio v2.1.1 and socket.io-redis v5.2.0 |
I am having the opposite effect: I can only see the logs for the namespaces. But I also connect the client to that namespaces. However I was expecting to be able to use a global middleware for auth. |
…#3197) When using a custom namespace with a middleware, the client did not receive the 'connect' event. Fixes socketio#3082
You want to:
Current behaviour
When using a custom namespace with a middleware the server gets a 'connection' event, but the client does not receive 'connect' event.
This works:
This does not work:
Sitenotes
Also very strange: If i do the following code then also the default-namespace does not emit any 'connect' event even tho the middleware from /admin is not running.
To fix this i have to add
.use((socket, next) => { next(); })
to default namespace. But still /admin does not emit 'connect'.Steps to reproduce (if the current behaviour is a bug)
Please see above
Expected behaviour
On connection, client should receive 'connect'
Setup
The text was updated successfully, but these errors were encountered: