Comments (5)
This middleware is for parsing HTTP requests; the stack trace is coming from where socket.io
is passing a socket object. This middleware is not a socket.io middleware, which is why you are having an issue.
from cookie-parser.
I'm also getting this 👍
from cookie-parser.
My code to make it this cookie-parser module work together with socket.io:
// ### Cookie parser
// Wrapper arround Express cookie parser, so we can use the same cookie parser for socket.io.
// Parse Cookie header and populate `socket.request.cookies` with an object keyed by the cookie names.
// Uses signed cookies by passing a secret string, which assigns `socket.request.secret` so it may be used by other middleware.
function cookieParserWrapper (socket, next) {
// request, response and callback
cookieParser(socket.request, {}, next);
}`
I hope it will help someone else!
Kind regards
Kristof
from cookie-parser.
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.
from cookie-parser.
The cookie-parser reference you pass as a passportSocketio.authorize({...})
configuration attribute will get the app crypto secret when it is invoked, not the request instance you'd expect. Therefore, do not create an instance of the cookie-parser. Instead simply get a reference to the library and pass that in.
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.
from cookie-parser.
Related Issues (20)
- Cookie Parser not reading signed cookies HOT 2
- Reading duplicated cookies HOT 5
- Docs on signedCookie seem to be off HOT 1
- How to sign a cookie manually? HOT 1
- create and remove cookies HOT 1
- Specific cookie kinda broken HOT 7
- cookieParser.signedCookie seems to not work properly HOT 5
- How to change/set domain, seems impossible? HOT 1
- Cookies values with "j:" prefix should not be parsed as JSON by default HOT 4
- signedCookie is unlikely to be used correctly HOT 1
- How do I clear the cookie(s)? HOT 1
- Inaccurate docs about JSONCookie, JSONCookies, signedCookie and signedCookies HOT 3
- Clear Cookies Feature? HOT 1
- My cookies automatically expire after 30 minutes HOT 1
- Get Metadata from cookie HOT 1
- [ FEATURE ] Support for ES6 imports HOT 1
- Provide types for the cookies in typescript HOT 5
- cookie 0.5.0 HOT 2
- Cookies not setting in production HOT 5
- Node.js v20.9.0 fetch API can't get set-cookie header set by cookie-parser HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cookie-parser.