Skip to content
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

Default namespace middleware firing #2342

Closed
perrin4869 opened this issue Dec 13, 2015 · 4 comments
Closed

Default namespace middleware firing #2342

perrin4869 opened this issue Dec 13, 2015 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@perrin4869
Copy link
Contributor

I'm trying to create a server with the default / namespace for normal users and the /admin namespace for admins, and they both are authenticated in different ways. I wrote two different middlewares for authentication like so:

io.use(normalAuthenicate);
io.of('/admin').use(adminAuthenticate);

Now, when connecting from the client I do:

var socket = io('/admin');

Unfortunately, the top middleware gets called even though it shouldn't be. It still gets called even if I change it to io.of('/').use(normalAuthenticate). Is there any way to tell socket.io to use only the middlewares for the namespaces requested?

@darrachequesne
Copy link
Member

Hi! I think a similar issue has already been opened here #2124

The middlewares associated with the default namespace '/' are indeed triggered by every request, and there's currently no way to avoid that. A quick "workaround" would be to also use a custom namespace for normal users 🍰

And yes, the documentation could be clearer on that point 😄

@perrin4869
Copy link
Contributor Author

I see I was hoping to avoid a new namespace, guess I have quite a bit of code to change now! Thankfully I also have tests to help me through the process :)

Is this done by design? I guess it kinda makes sense to have a namespace with common middleware in case you got some common logic. But definitely this needs documentation

@nkzawa nkzawa added documentation Improvements or additions to documentation Namespaces labels Jan 17, 2016
@darrachequesne
Copy link
Member

That issue was closed automatically. Please check if your issue is fixed with the latest release, and reopen if needed (with a fiddle reproducing the issue if possible).

@perrin4869
Copy link
Contributor Author

@darrachequesne I think this issue should still be addressed, preferably by fixing the inconsistencies between the root namespace / and custom namespaces as described in #2124 and also my own issue socketio/socket.io-client#975
Maybe this could be added to the list in #2823?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants
@nkzawa @perrin4869 @darrachequesne and others