Giter Site home page Giter Site logo

Comments (5)

dougwilson avatar dougwilson commented on April 28, 2024

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.

danpe avatar danpe commented on April 28, 2024

I'm also getting this 👍

from cookie-parser.

Stofkn avatar Stofkn commented on April 28, 2024

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.

dougwilson avatar dougwilson commented on April 28, 2024

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.

rmethlie avatar rmethlie commented on April 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.