-
Notifications
You must be signed in to change notification settings - Fork 47
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 Not Fired Before "connection" event #16
Comments
The I'm going to leave this open though as I think the middleware application code could do with a bit of thought, which would include adding the middleware stack to all events. |
To give a bit more context: I have a global session store which I look at to decide if the user is authenticated. Users should receive "authentication error" before they receive the connection. Does this seem reasonable? |
For some reason, I wasn't aware that I had access to the handshake. Now I'm doing something like:
|
This put me on the right track, but to highlight a bit more the "do stuff with ctx.socket.handshake.headers.cookie to validate authentication", which was not really straight forward, this is how I solved it, by basically using the same mechanism than Koa: import Cookies from 'cookies'
//....
io.on( 'connection', ctx => {
const cookies = new Cookies( ctx.socket.handshake, null, {keys: app.keys } )
if(!cookies.get('koa:sess', {signed: true})) {
ctx.socket.disconnect()
}
}) |
Pardon my ignorance, but why aren't middlewares fired before the
connection
event? If this isn't clear, I have an example handy.Should my client simply trigger a separate event once it has received a connected event or something? Thanks in advance.
The text was updated successfully, but these errors were encountered: