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
Cannot read property 'cookie' of undefined #3
Comments
This middleware is for parsing HTTP requests; the stack trace is coming from where |
I'm also getting this 👍 |
My code to make it this cookie-parser module work together with socket.io:
I hope it will help someone else! Kind regards |
I don't know how to use socket.io, but this module requires an HTTP request as the first argument, and node.js core itself adds a headers property. If you are getting this error, you are simply using this module incorrectly with socket.io, because you are using it somewhere that is not giving it a HTTP request. |
The cookie-parser reference you pass as a So don't do this app.io.use(passportSocketIO.authorize({
passport: passport,
cookieParser: require('cookie-parser')(config.cryptoKey),
... That results in the error you are seeing because the cookie-parser will now expect a request as an argument. Instead do this: app.io.use(passportSocketIO.authorize({
passport: passport,
cookieParser: require('cookie-parser'), // dont init, let passport.socketio do that for you Hope that helps. |
Hi
I'm currently working with socket.io and the client sends a request but apperently the req.headers is undefined.
So in the index.js file on line 27, I would suggest to do a check if the request object has headers and then take cookie of the headers.
If there are no headers raise an exception and pass it to the callback.
Thanks!
The text was updated successfully, but these errors were encountered: